· 7 years ago · Jan 18, 2019, 07:22 AM
1drop database if exists ti3_metro;
2create database if not exists ti3_metro;
3use ti3_metro;
4
5create table operator(
6id smallint not null primary key,
7nazwa varchar(32) not null
8);
9create table linia_metra(
10id smallint not null primary key,
11nazwa varchar(32) not null,
12operatorId smallint not null
13);
14create table stacja(
15id smallint not null primary key,
16nazwa varchar(32) not null,
17liniaMetraId smallint not null,
18isActive char(1) not null default '1',
19passThrough char(1) not null default '0'
20);
21create table stacja_realcje(
22id smallint not null primary key,
23aktStacjaId smallint not null,
24docelStacjaId smallint not null,
25czasPrzejazdu smallint not null,
26dystans integer not null
27);
28alter table linia_metra add constraint
29foreign key fk_operatorId(operatorId)
30references operator(id)
31on update restrict on delete restrict;
32
33alter table stacja add constraint
34foreign key fk_linia_metra(linia_metraId)
35references linia_metra(id)
36on update restrict on delete restrict;
37
38alter table stacje_relacje add constraint
39foreign key fk_aktStacjaId(aktStacjaId)
40references stacja(id)
41on update restrict on delete restrict;
42
43alter table stacje_relacje add constraint
44foreign key fk_docelStacjaId(docelStacjaId)
45references stacja(id)
46on update restrict on delete restrict;
47
48
49
50insert into operator values (1, upper('operator '));