· 5 years ago · Mar 05, 2020, 02:42 PM
1drop table if exists init_results cascade;
2drop table if exists grandprix cascade;
3drop table if exists baseline cascade;
4drop table if exists results cascade;
5drop table if exists pilot cascade;
6
7create table init_results (
8 GRANDPRIXID INTEGER,
9 GRANDPRIXNAME TEXT,
10 BASELINEPOSITION INTEGER,
11 CARNAME TEXT,
12 PILOTID INTEGER,
13 PILOTNAME TEXT
14);
15
16INSERT INTO init_results VALUES (1, 'GRANDPRIX MONAKO', 56, 'MACLAREN', 123, 'N. LAUDA');
17INSERT INTO init_results VALUES (2, 'GRANDPRIX VIETNAM', 56, 'FERRARI', 124, 'N. LAUDA');
18
19select * from init_results;
20
21create table grandprix(
22 GRANDPRIXID INTEGER primary key not null,
23 GRANDPRIXNAME TEXT
24);
25
26create table results(
27 GRANDPRIXID INTEGER not null,
28 BASELINEPOSITION INTEGER not null,
29 primary key(GRANDPRIXID,BASELINEPOSITION)
30);
31
32create table pilot(
33 PILOTID INTEGER primary key not null,
34 PILOTNAME TEXT
35);
36
37create table baseline(
38 BASELINEPOSITION INTEGER not null,
39 CARNAME TEXT,
40 PILOTID INTEGER references pilot(PILOTID),
41 primary key(BASELINEPOSITION,CARNAME)
42);
43
44insert into grandprix values(1, 'GRANDPRIX MONAKO');
45insert into grandprix values(2, 'GRANDPRIX VIETNAM');
46
47insert into pilot values(123, 'N. LAUDA');
48insert into pilot values(124, 'N. LAUDA');
49
50insert into baseline values(56, 'MACLAREN', 123);
51insert into baseline values(56, 'FERRARI', 124);
52
53insert into results values(1,56);
54insert into results values(2,56);
55
56select * from grandprix;
57select * from results;
58select * from pilot;
59select * from baseline;