Advertisement
OIQ

hw7_ddl

OIQ
Dec 14th, 2022
873
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. DROP TABLE "Countries";
  2. DROP TABLE "Olympics";
  3. DROP TABLE "Players";
  4. DROP TABLE "Events";
  5. DROP TABLE "Results";
  6.  
  7. CREATE TABLE "Countries" (
  8.     name varchar(40),
  9.     country_id varchar(3) UNIQUE,
  10.     area_sqkm integer,
  11.     population integer
  12. );
  13.  
  14. CREATE TABLE "Olympics" (
  15.     olympic_id char(7) unique,
  16.     country_id char(3),
  17.     city char(50),
  18.     year integer,
  19.     startdate date,
  20.     enddate date,
  21.     FOREIGN KEY (country_id) REFERENCES "Countries" (country_id)
  22. );
  23.  
  24. CREATE TABLE "Players" (
  25.     name char(40),
  26.     player_id char(10) unique,
  27.     country_id char(3),
  28.     birthdate date,
  29.     FOREIGN KEY (country_id) REFERENCES "Countries" (country_id)
  30. );
  31.  
  32. CREATE TABLE "Events" (
  33.     event_id char(7) unique,
  34.     name char(40),
  35.     eventtype char(20),
  36.     olympic_id char(7),
  37.     is_team_event integer check (is_team_event in (0, 1)),
  38.     num_players_in_team integer,
  39.     result_noted_in char(100),
  40.     FOREIGN KEY (olympic_id) REFERENCES "Olympics" (olympic_id)
  41. );
  42.  
  43. CREATE TABLE "Results" (
  44.     event_id char(7),
  45.     player_id char(10),
  46.     medal char(7),
  47.     result float,
  48.     FOREIGN KEY (event_id) REFERENCES "Events" (event_id),
  49.     FOREIGN KEY (player_id) REFERENCES "Players" (player_id)
  50. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement