-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathsql.txt
162 lines (139 loc) · 3.82 KB
/
sql.txt
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
CREATE TABLE Department
(
DCode VARCHAR(5) NOT NULL,
DName VARCHAR(20) NOT NULL,
PRIMARY KEY (DCode)
);
CREATE TABLE Student
(
RollNo INTEGER NOT NULL,
SName VARCHAR(30) NOT NULL,
Batch YEAR NOT NULL,
Branch VARCHAR(5) NOT NULL,
DoB DATE NOT NULL,
PRIMARY KEY (RollNo),
FOREIGN KEY (Branch) REFERENCES Department(DCode)
)
CREATE TABLE BG
(
BloodG VARCHAR(5) NOT NULL,
PRIMARY KEY(BloodG)
)
ALTER TABLE student
ADD(
BloodG VARCHAR(5),
FOREIGN KEY(BloodG) REFERENCES bg(BloodG)
)
CREATE TABLE Faculty
(
FID INTEGER NOT NULL,
FName VARCHAR(30) NOT NULL,
Dept VARCHAR(5) NOT NULL,
DoB DATE NOT NULL,
BloodG VARCHAR(5),
FOREIGN KEY (BloodG) REFERENCES bg(BloodG),
PRIMARY KEY (FID),
FOREIGN KEY (Dept) REFERENCES Department(DCode)
)
CREATE TABLE Staff
(
EID INTEGER NOT NULL,
EName VARCHAR(30) NOT NULL,
DoB DATE NOT NULL,
BloodG VARCHAR(5),
FOREIGN KEY (BloodG) REFERENCES bg(BloodG),
PRIMARY KEY (EID)
)
CREATE TABLE p_type
(
type VARCHAR(15) NOT NULL,
PRIMARY KEY (type)
);
CREATE TABLE passenger
(
ID INTEGER NOT NULL,
Type VARCHAR(15) NOT NULL,
PRIMARY KEY (ID, type),
FOREIGN KEY(Type) REFERENCES p_type(type)
)
ALTER TABLE student
ADD FOREIGN KEY (RollNo) REFERENCES passenger(ID)
ALTER TABLE faculty
ADD FOREIGN KEY (FID) REFERENCES passenger(ID);
ALTER TABLE staff
ADD FOREIGN KEY (EID) REFERENCES passenger(ID)
CREATE TABLE Guest
(
GID INTEGER NOT NULL,
GName VARCHAR(30) NOT NULL,
DoB DATE NOT NULL,
HostID INTEGER NOT NULL,
HostType VARCHAR(15) NOT NULL,
BloodG VARCHAR(5) NOT NULL,
FOREIGN KEY (BloodG) REFERENCES bg(BloodG),
PRIMARY KEY (GID),
FOREIGN KEY (HostID) REFERENCES passenger(ID),
FOREIGN KEY (HostType) REFERENCES passenger(Type),
FOREIGN KEY (GID) REFERENCES passenger(ID)
)
CREATE TABLE STOPS
(
StopName VARCHAR(20) NOT NULL,
StopType VARCHAR(10) NOT NULL,
PRIMARY KEY (StopName)
)
CREATE TABLE Routes
(
RID INTEGER NOT NULL,
STime TIME,
DTime TIME,
Src VARCHAR(20),
Dst VARCHAR(20),
Capacity INTEGER,
PRIMARY KEY (RID),
FOREIGN KEY (Src) REFERENCES Stops(StopName),
FOREIGN KEY (Dst) REFERENCES Stops(StopName)
)
CREATE TABLE bus_instances
(
BID INTEGER NOT NULL,
RID INTEGER NOT NULL,
Capacity INTEGER NOT NULL,
BusDate DATE,
DepTime TIME,
PRIMARY KEY (BID),
FOREIGN KEY (RID) REFERENCES routes(RID),
FOREIGN KEY (Capacity) REFERENCES routes(Capacity),
FOREIGN KEY (DepTime) REFERENCES routes(DTime)
)
CREATE TABLE Seat_Matrix
(
BID INTEGER NOT NULL,
RID INTEGER NOT NULL,
SeatNo INTEGER NOT NULL,
Passenger INTEGER DEFAULT NULL,
PRIMARY KEY (BID, RID, SeatNo),
FOREIGN KEY (RID) REFERENCES routes(RID),
FOREIGN KEY (Passenger) REFERENCES passenger(ID)
)
INSERT INTO p_type VALUES ('Student'), ('Faculty' ), ('Staff'), ('Guest')
INSERT INTO bg VALUES ('A+'), ('A-' ), ('B+'), ('B-'), ('AB+'), ('AB-'), ('O+'), ('O-')
ALTER TABLE department MODIFY COLUMN DName VARCHAR(50)
INSERT INTO department VALUES
('CSE' , 'Computer Science and Engineering'),
('ECE' , 'Electronics and Communication Engineering'),
('ME' , 'Mechanical Engineering'),
('NS' , 'Natural Sciences');
INSERT INTO department VALUES ('DS', 'Design')
INSERT INTO stops VALUES
('PG Hostel', 'Institute'),
('Hall 4', 'Institute'),
('Nescafe (Hall 1)', 'Institute'),
('Hexagon Canteen', 'Institute'),
('Narmada Residency', 'Institute'),
('IIITDMJ Main Gate', 'Institute'),
('Railway Station', 'City'),
('Empire Talkies', 'City'),
('Russel Chowk', 'City'),
('Penty Naka', 'City')
ALTER TABLE passenger ADD pwd VARCHAR(40)