-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.sql
More file actions
240 lines (161 loc) · 6.49 KB
/
Main.sql
File metadata and controls
240 lines (161 loc) · 6.49 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
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
IF NOT EXISTS
(SELECT * FROM sys.databases WHERE name = 'Project')
BEGIN
CREATE DATABASE Project;
END;
Use Project;
________________________________________________________________________________
-- Table Structure for Administartor Table.
IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='Admin' )
CREATE TABLE Admin (
Admin_ID BIGINT Primary Key Not Null,
Student_ID BIGINT ,
Student_Name VARCHAR(20),
Student_Password VARCHAR(20)
);
________________________________________________________________________________
-- Table Structure for Student Table.
IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='Student' )
CREATE TABLE Student (
Student_ID BIGINT Primary Key Not Null,
Student_Name VARCHAR(20),
Address VARCHAR(50),
Contact_No BIGINT,
Departement_ID BIGINT,
Course_ID BIGINT
);
________________________________________________________________________________
-- Table Structure for Fee Table.
IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='Fee' )
CREATE TABLE Fee (
Challan_No BIGINT Primary Key IDENTITY(1,1),
Student_ID BIGINT,
Student_Name VARCHAR(20),
Tution_Fee BIGINT
);
________________________________________________________________________________
-- Table Structure for Teacher Table.
IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='Teacher' )
CREATE TABLE Teacher (
Teacher_ID BIGINT Primary Key Not Null,
Teacher_Name VARCHAR(20),
Student_ID BIGINT
);
________________________________________________________________________________
-- Table Structure for Course Table.
IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='Course' )
CREATE TABLE Course (
Course_ID BIGINT Primary Key Not Null,
Course_Name VARCHAR(20),
Teacher_ID BIGINT,
Student_ID BIGINT
);
________________________________________________________________________________
-- Table Structure for Department Table.
IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='Department' )
CREATE TABLE Department (
Departement_ID BIGINT Primary Key Not Null,
Department_Name VARCHAR(20),
Course_ID BIGINT,
Exam_ID BIGINT
);
________________________________________________________________________________
-- Table Structure for Exam Table.
IF NOT EXISTS (SELECT * FROM sysobjects WHERE name='Exam' )
CREATE TABLE Exam (
Exam_ID BIGINT Primary Key Not Null,
Exam_Name VARCHAR(20),
Course_ID BIGINT,
Student_ID BIGINT,
Marks BIGINT
);
________________________________________________________________________________
-- Declaring Foreign Key For Admin Table
Alter TABLE Admin
CONSTRAINT Fk_Student_ID FOREIGN KEY (Student_ID)
REFERENCES Student (Student_ID)
CONSTRAINT Fk_Student_Name FOREIGN KEY (Student_Name)
REFERENCES Student (Student_Name)
________________________________________________________________________________
-- Declaring Foreign Key For Student Table
Alter TABLE Student
CONSTRAINT Fk_Course_ID FOREIGN KEY (Course_ID)
REFERENCES Course (Course_ID)
CONSTRAINT Fk_Departement_ID FOREIGN KEY (Departement_ID)
REFERENCES Department (Departement_ID)
________________________________________________________________________________
-- Declaring Foreign Key For Teacher Table
Alter TABLE Teacher
CONSTRAINT Fk_Student_ID FOREIGN KEY (Student_ID)
REFERENCES Student (Student_ID)
________________________________________________________________________________
-- Declaring Foreign Key For Coursr Table
Alter TABLE Coures
CONSTRAINT Fk_Student_ID FOREIGN KEY (Student_ID)
REFERENCES Student (Student_ID)
CONSTRAINT Fk_Teacher_ID FOREIGN KEY (Teacher_ID)
REFERENCES Teacher (Teacher_ID)
________________________________________________________________________________
-- Declaring Foreign Key For Department Table
ALTER TABLE Department
CONSTRAINT Fk_Course_ID FOREIGN KEY (Course_ID)
REFERENCES Course (Course_ID)
________________________________________________________________________________
-- Declaring Foreign Key For Exam Table
Alter TABLE Exam
CONSTRAINT Fk_Student_ID FOREIGN KEY (Student_ID)
REFERENCES Student (Student_ID)
CONSTRAINT Fk_Course_ID FOREIGN KEY (Course_ID)
REFERENCES Course (Course_ID)
________________________________________________________________________________
-- Declaring Foreign Key For Fee Table
Alter TABLE Fee
CONSTRAINT Fk_Student_ID FOREIGN KEY (Student_ID)
REFERENCES Student (Student_ID)
CONSTRAINT Fk_Student_Name FOREIGN KEY (Student_Name)
REFERENCES Student (Student_Name)
________________________________________________________________________________
-- Dumping Data into Admin Table
INSERT INTO Admin
VALUES
(1 , 010 , 'Armoghan' , 'Armoghan_Password'),
(2 , 033 , 'Aftab Shah' , 'Aftab_Password');
________________________________________________________________________________
-- Dumping Data into Student Table
INSERT INTO Student
VALUES
(1 , 'Armoghan' , 'Lahore' , '0333 0000000' 2 , 3 ),
(2 , 'Aftab Hussain' , 'Lahore' , '0333 0000001' 2 , 3 );
________________________________________________________________________________
-- Dumping Data into Department Table
INSERT INTO Department
VALUES
(1 , 'Bs CS' , 1 , 3 ),
(2 , 'Bs IT' , 3 , 2),
(3 , 'Bs DFCS' 2 , 1),
);
________________________________________________________________________________
-- Dumping Data into Teacher Table
INSERT INTO Teacher
VALUES
(1 , 'Imran Khalid' , 2 ),
(2 , 'Saud Bin Farooq' , 1 );
________________________________________________________________________________
-- Dumping Data into Fee Table
INSERT INTO Fee ( Student_Id , Student_Name , Tution_Fee)
VALUES
(1 , 'Armoghan' , 50000 ),
(2 , 'Afta Hussain' , 50000 );
________________________________________________________________________________
-- Dumping Data into Exam Table
INSERT INTO Exam
VALUES
(1 , 'Mids' , 1 , 1 , 80 ),
(2 , 'Finals' , 2 , 1 , 80 );
________________________________________________________________________________
-- Dumping Data into Course Table
INSERT INTO Course
VALUES
(1 , 'Fa-21' , 1 , 2 ),
(2 , 'Sp-21' , 2 , 1 );
________________________________________________________________________________