-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.sql
More file actions
101 lines (86 loc) · 2.77 KB
/
schema.sql
File metadata and controls
101 lines (86 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
------------------------------------------------------
-- SCHEMA: olympics
------------------------------------------------------
DROP SCHEMA IF EXISTS olympics CASCADE;
CREATE SCHEMA olympics;
SET SCHEMA olympics;
DROP TABLE IF EXISTS OLYMPIAD CASCADE;
DROP TABLE IF EXISTS COUNTRY CASCADE;
DROP TABLE IF EXISTS SPORT CASCADE;
DROP TABLE IF EXISTS PARTICIPANT CASCADE;
DROP TABLE IF EXISTS ACCOUNT CASCADE;
DROP TABLE IF EXISTS TEAM_MEMBERS CASCADE;
DROP TABLE IF EXISTS TEAM CASCADE;
DROP TABLE IF EXISTS EVENTS CASCADE;
DROP TABLE IF EXISTS VENUE CASCADE;
DROP TABLE IF EXISTS MEDAL CASCADE;
DROP TABLE IF EXISTS PLACEMENT CASCADE;
/*
TABLE: OLYMPIAD
Format: (olympiad_num, city, country, opening_date, closing_date, website)
*/
CREATE TABLE OLYMPIAD (
olympiad_num VARCHAR(30) PRIMARY KEY,
city VARCHAR(30) NOT NULL,
country CHAR(3) NOT NULL FOREIGN KEY, --country code for reference to country table
opening_date TIMESTAMP NOT NULL,
closing_date TIMESTAMP NOT NULL,
website VARCHAR(30) NOT NULL,
CONSTRAINT olympiad_pk PRIMARY KEY (olympiad_num), --checks that the olympiad number is unique and not null
CONSTRAINT olympiad_country_fk FOREIGN KEY (country) REFERENCES COUNTRY(country_code) --checks that the country code is a valid country code
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
);
/*
TABLE: COUNTRY
Format: (country_code, country_name)
*/
CREATE TABLE COUNTRY (
country_code CHAR(3) PRIMARY KEY,
country_name VARCHAR(30) NOT NULL,
CONSTRAINT country_pk PRIMARY KEY (country_code) --checks that the country code is unique and not null
);
/*
TABLE: SPORT
Format: (sport_id, sport_name, description, team_size, date_added)
*/
CREATE TABLE SPORT (
sport_id SERIAL PRIMARY KEY,
sport_name VARCHAR(30) NOT NULL,
description VARCHAR(3kl0),
team_size INT NOT NULL,
date_added TIMESTAMP NOT NULL,
CONSTRAINT sport_pk PRIMARY KEY (sport_id) --checks that the sport id is unique and not null
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?
);
/*
TABLE: PARTICIPANT
Format: (participant_id, acount, first, middle, last, birth_country, dob, gender)
*/
/*
TABLE: ACCOUNT
Format: (account_id, username, passkey, role, last_login)
*/
/*
TABLE: TEAM_MEMBERS
Format: (team, participant)
*/
/*
TABLE: TEAM
Format: (team_id, olympiad, sport, coach, country, gender, eligible)
*/
/*
TABLE: EVENTS
Format: (event_id, venue, olympiad, sport, gender, date)
*/
/*
TABLE: VENUE
Format: (venue_name, capacity)
*/
/*
TABLE: MEDAL
Format: (medal_id, type, points)
*/
/*
TABLE: PLACEMENT
Format: (event, team, medal, position)
*/