· 5 years ago · Mar 11, 2020, 01:30 AM
1drop table if exists GRANDPRIX cascade;
2drop table if exists RESULTS cascade;
3drop table if exists CAR cascade;
4drop table if exists PILOT cascade;
5
6
7
8
9create table GRANDPRIX (
10 GRANDPRIXID integer not null,
11 GRANDPRIXNAME text not null,
12 primary key(GRANDPRIXID)
13 );
14
15create table CAR (
16 BASELINEPOSITION integer not null,
17 CARNAME text not null,
18 primary key(BASELINEPOSITION, CARNAME)
19 );
20
21create table RESULTS (
22 GRANDPRIXID integer not null references GRANDPRIX(GRANDPRIXID),
23 BASELINEPOSITION integer not null references CAR(BASELINEPOSITION),
24 primary key(GRANDPRIXID,BASELINEPOSITION)
25 );
26
27
28create table PILOT (
29 PILOTID integer not null,
30 PILOTNAME text not null,
31 primary key(PILOTID)
32 );
33
34insert into GRANDPRIX values(1, 'GRANDPRIX MONAKO'),(2, 'GRANDPRIX VIETNAM');
35insert into CAR values(56, 'MACLAREN'),(56, 'FERRARI');
36insert into RESULTS values(1,56),(2,56);
37insert into PILOT values(123,'N.LAUDA'),(124,'N.LAUDA');
38
39
40select * from pilot