leg209420
leg209420

Reputation: 1

Creating tables in SQL with the corresponding attributes, from an ER model

If I have an ERD: https://i.stack..com/gj3Sn.png

Which I'm trying to type up in postgres SQL. How could this be done?

So far i've got:

Upvotes: 0

Views: 128

Answers (1)

The Impaler
The Impaler

Reputation: 48875

You have a few typos in the CREATE TABLE ... statements.

They work with a few changes. See below:

CREATE TABLE TradingRoute (
  OperatingCompany integer, 
  MonitoringKey text,
  LastYearRevenue integer,
  Taxes integer ,
  Fleet_size integer,
  PRIMARY KEY (MonitoringKey)
);

CREATE TABLE Planet (
  Population integer, 
  Name text ,
  PlanetID integer ,
  StarSystem integer,
  PRIMARY KEY (PlanetID)
);

CREATE TABLE SpaceStation (
  OperatingCompany integer,
  StationID integer ,
  Longitude integer ,
  Name text ,
  Latitude integer,
  PRIMARY KEY (StationID)
);

CREATE TABLE Product (
  VolumePerTon integer,
  Name text ,
  ValuePerTon integer,
  ProductID text ,
  PRIMARY KEY (ProductID)
);

CREATE TABLE RawMaterial (
  FundamentalOrComposite integer,
  State Date
);

CREATE TABLE Batch (
  BatchID integer,
  ExtractionOrManufacturingDate Date ,
  PRIMARY KEY (BatchID)
);

See them running at DB Fiddle.

Upvotes: 1

Related Questions