Skip to content

Commit ba6a4dc

Browse files
committed
Started the schema tables
1 parent 40d208e commit ba6a4dc

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed

schema.sql

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
------------------------------------------------------
2+
-- SCHEMA: olympics
3+
------------------------------------------------------
4+
5+
DROP SCHEMA IF EXISTS olympics CASCADE;
6+
CREATE SCHEMA olympics;
7+
SET SCHEMA olympics;
8+
9+
DROP TABLE IF EXISTS OLYMPIAD CASCADE;
10+
DROP TABLE IF EXISTS COUNTRY CASCADE;
11+
DROP TABLE IF EXISTS SPORT CASCADE;
12+
DROP TABLE IF EXISTS PARTICIPANT CASCADE;
13+
DROP TABLE IF EXISTS ACCOUNT CASCADE;
14+
DROP TABLE IF EXISTS TEAM_MEMBERS CASCADE;
15+
DROP TABLE IF EXISTS TEAM CASCADE;
16+
DROP TABLE IF EXISTS EVENTS CASCADE;
17+
DROP TABLE IF EXISTS VENUE CASCADE;
18+
DROP TABLE IF EXISTS MEDAL CASCADE;
19+
DROP TABLE IF EXISTS PLACEMENT CASCADE;
20+
21+
22+
/*
23+
TABLE: OLYMPIAD
24+
Format: (olympiad_num, city, country, opening_date, closing_date, website)
25+
*/
26+
CREATE TABLE OLYMPIAD (
27+
olympiad_num VARCHAR(30) PRIMARY KEY,
28+
city VARCHAR(30) NOT NULL,
29+
country CHAR(3) NOT NULL FOREIGN KEY, --country code for reference to country table
30+
opening_date TIMESTAMP NOT NULL,
31+
closing_date TIMESTAMP NOT NULL,
32+
website VARCHAR(30) NOT NULL,
33+
CONSTRAINT olympiad_pk PRIMARY KEY (olympiad_num), --checks that the olympiad number is unique and not null
34+
CONSTRAINT olympiad_country_fk FOREIGN KEY (country) REFERENCES COUNTRY(country_code) --checks that the country code is a valid country code
35+
CONSTRAINT olympiad_opening_date_chk CHECK ((opening_date <= closing_date) OR (closing_date IS NULL)) --checks that the opening date is before the closing date
36+
);
37+
38+
/*
39+
TABLE: COUNTRY
40+
Format: (country_code, country_name)
41+
*/
42+
CREATE TABLE COUNTRY (
43+
country_code CHAR(3) PRIMARY KEY,
44+
country_name VARCHAR(30) NOT NULL,
45+
CONSTRAINT country_pk PRIMARY KEY (country_code) --checks that the country code is unique and not null
46+
);
47+
48+
/*
49+
TABLE: SPORT
50+
Format: (sport_id, sport_name, description, team_size, date_added)
51+
*/
52+
CREATE TABLE SPORT (
53+
sport_id SERIAL PRIMARY KEY,
54+
sport_name VARCHAR(30) NOT NULL,
55+
description VARCHAR(3kl0),
56+
team_size INT NOT NULL,
57+
date_added TIMESTAMP NOT NULL,
58+
CONSTRAINT sport_pk PRIMARY KEY (sport_id) --checks that the sport id is unique and not null
59+
CONSTRAINT sport_team_size_chk CHECK ((team_size > 0) OR (team_size > 100)) --checks that the team size is greater than 0 and less than ... idk maybe 100?
60+
);
61+
62+
/*
63+
TABLE: PARTICIPANT
64+
Format: (participant_id, acount, first, middle, last, birth_country, dob, gender)
65+
*/
66+
67+
/*
68+
TABLE: ACCOUNT
69+
Format: (account_id, username, passkey, role, last_login)
70+
*/
71+
72+
/*
73+
TABLE: TEAM_MEMBERS
74+
Format: (team, participant)
75+
*/
76+
77+
/*
78+
TABLE: TEAM
79+
Format: (team_id, olympiad, sport, coach, country, gender, eligible)
80+
*/
81+
82+
/*
83+
TABLE: EVENTS
84+
Format: (event_id, venue, olympiad, sport, gender, date)
85+
*/
86+
87+
/*
88+
TABLE: VENUE
89+
Format: (venue_name, capacity)
90+
*/
91+
92+
/*
93+
TABLE: MEDAL
94+
Format: (medal_id, type, points)
95+
*/
96+
97+
/*
98+
TABLE: PLACEMENT
99+
Format: (event, team, medal, position)
100+
*/
101+

0 commit comments

Comments
 (0)