· 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);
9
10create table linia_metra(
11id smallint not null primary key,
12nazwa varchar(32) not null,
13operatorId smallint not null);
14
15create table stacja(
16id smallint not null primary key,
17nazwa varchar(32) not null,
18liniaMetraId smallint not null,
19isActive char(1) not null default '1',
20passThrough char(1) not null default '0');
21
22create table stacje_relacje(
23id smallint not null primary key,
24aktStacjaId smallint not null,
25docelStacjaId smallint not null,
26czasPrzejazdu smallint not null,
27dystans integer not null);
28
29alter table linia_metra add constraint foreign key fk_operatorId(operatorId) references operator(id) on update restrict on delete restrict;
30alter table stacja add constraint foreign key fk_liniaMetraId(liniaMetraId) references linia_Metra(id) on update restrict on delete restrict;
31alter table stacje_relacje add constraint foreign key fk_docelStacjaId(docelStacjaId) references stacja(id) on update restrict on delete restrict;
32
33insert into operator values (1, upper('operator 1'));