forked from AjayRajNelapudi/BusBooking-API
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreatedb.sql
More file actions
executable file
·56 lines (56 loc) · 1.52 KB
/
createdb.sql
File metadata and controls
executable file
·56 lines (56 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
-- Create Database --
create database BusBooking;
-- Navigating to Database --
use BusBooking;
-- Creating Bus Table --
create table Bus (
bid integer primary key,
bno varchar(10) unique not null,
btype varchar(10) not null
);
-- Creating Routes Table --
create table Route (
rno integer primary key,
source varchar(30) not null,
destination varchar(30) not null
);
-- Create Relation b/w bus and routes --
create table Service (
sid integer auto_increment primary key,
bid integer not null,
rno integer not null,
source_time time not null,
destination_time time not null,
sunday char(1),
monday char(1),
tuesday char(1),
wednesday char(1),
thursday char(1),
friday char(1),
saturday char(1)
);
-- Adding foreign keys --
alter table Service
add constraint bus_fk foreign key(bid) references Bus(bid),
add constraint rno_fk foreign key(rno) references Route(rno);
-- Creating Customer table --
create table Customer (
cid integer auto_increment primary key,
fname varchar(30) not null,
lname varchar(30) not null,
phone varchar(10) not null,
email varchar(30),
username varchar(20) unique not null,
password varchar(20) not null
);
-- Creating Booking Table --
create table Booking (
cid integer not null,
sid integer not null,
seat1 integer not null,
seat2 integer
);
-- Adding foreign keys --
alter table Booking
add constraint cid_fk_ foreign key(cid) references Customer(cid),
add constraint sid_fk_ foreign key(sid) references Service(sid);