source: liacs/db/opdr1/generate.sql@ 399

Last change on this file since 399 was 2, checked in by Rick van der Zwet, 15 years ago

Initial import of data of old repository ('data') worth keeping (e.g. tracking
means of URL access statistics)

  • Property svn:executable set to *
File size: 2.5 KB
Line 
1--name: Rick van der Zwet
2--sid: 0433373
3--file: generate.sql
4--vak/opdracht: Databases/ opdracht 1
5
6CREATE TABLE Coach(
7 ID integer,
8 Age integer,
9 Name char(20),
10 PRIMARY KEY( ID )
11);
12
13
14CREATE TABLE Sportsman(
15 ID integer,
16 Age integer,
17 Name char(20),
18 Country char(20),
19 Coach_id integer NOT NULL,
20 PRIMARY KEY( ID ),
21 FOREIGN KEY( Coach_id ) REFERENCES Coach( ID )
22);
23
24
25CREATE TABLE Sponsor(
26 ID integer,
27 Name char(20),
28 SupportSportsman_id integer,
29 Budget integer,
30 PRIMARY KEY( ID ),
31 FOREIGN KEY( SupportSportsman_id ) REFERENCES Sportsman( ID )
32);
33
34
35CREATE TABLE Sports_Branch(
36 Name char(20),
37 PRIMARY KEY( Name )
38);
39
40
41CREATE TABLE plays(
42 Sportsman_id integer,
43 Sports_Branch char(20),
44 PRIMARY KEY( Sportsman_id, Sports_Branch ),
45 FOREIGN KEY( Sportsman_id ) REFERENCES Sportsman( ID ) ON DELETE CASCADE,
46 FOREIGN KEY( Sports_Branch ) REFERENCES Sports_Branch( Name ) ON DELETE CASCADE
47);
48
49
50CREATE TABLE Sports_event(
51 ID integer,
52 Datum date,
53 Name char(20),
54 Location char(20),
55 PRIMARY KEY( ID )
56);
57
58
59CREATE TABLE participate(
60 Sportsman_id integer,
61 SportsEvent_id integer,
62 PRIMARY KEY( Sportsman_id, SportsEvent_id ),
63 FOREIGN KEY( Sportsman_id ) REFERENCES Sportsman( ID ) ON DELETE CASCADE,
64 FOREIGN KEY( SportsEvent_id ) REFERENCES Sports_event ( ID ) ON DELETE CASCADE
65);
66
67CREATE TABLE won(
68 Sportsman_id integer,
69 Sports_event integer,
70 Sports_Branch char(20),
71 Metal char(20),
72 PRIMARY KEY( Sportsman_id, Sports_event, Sports_Branch ),
73 FOREIGN KEY( Sportsman_id ) REFERENCES Sportsman( ID ) ON DELETE CASCADE,
74 FOREIGN KEY( Sports_event ) REFERENCES Sports_event( ID ) ON DELETE CASCADE,
75 FOREIGN KEY( Sports_Branch ) REFERENCES Sports_Branch( Name ) ON DELETE CASCADE
76);
77
78
79--
80--budget VIEW is een beetje in elkaar gehacked
81--niet geheel duidelijk wat bedoeld werd.
82--de view lijkt me wat overbodig hier,
83--dit kan beter extern geregeld worden.
84--
85
86CREATE TABLE Sponsor_login(
87 Name char(20),
88 Passwd char(20),
89 Sponsor_id integer,
90 PRIMARY KEY ( Name ),
91 FOREIGN KEY( Sponsor_id ) REFERENCES Sponsor( ID ) ON DELETE CASCADE
92);
93
94CREATE VIEW budget( Name, Support_Sportsman_id, Budget )
95 AS SELECT S.Name, S.SupportSportsman_id, S.Budget
96 FROM Sponsor S, Sponsor_login L
97 WHERE L.sponsor_id = S.ID AND L.Passwd = 'externe_variable'
98;
99
100DROP VIEW budget;
101DROP TABLE sponsor_login;
102
103--
104--END of HACK
105--
106
107
108DROP TABLE won;
109DROP TABLE participate;
110DROP TABLE Sports_event;
111DROP TABLE plays;
112DROP TABLE Sports_Branch;
113DROP TABLE Sponsor;
114DROP TABLE Sportsman;
115DROP TABLE Coach;
116
Note: See TracBrowser for help on using the repository browser.