-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest
62 lines (46 loc) · 1.57 KB
/
test
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
-- Initializing Database
create database University;
-- Create Student Table
CREATE TABLE student(
id INT NOT NULL,
name VARCHAR (20) NOT NULL,
age INT NOT NULL,
address CHAR (25) ,
gender CHAR(1)NOT NULL,
gpa DECIMAL(4,3) NOT NULL,
ref_college INT references college(idc),
ref_department INT references specialzation(ids),
PRIMARY KEY (id)
);
-- Add forein keys and relation
ALTER TABLE student
ADD FOREIGN KEY (ref_college) REFERENCES college (idc),
ADD FOREIGN KEY (ref_department) REFERENCES specialzation (ids);
-- Create College Table
CREATE TABLE college (
idc INT NOT NULL,
name VARCHAR (20) NOT NULL,
PRIMARY KEY (idc)
);
-- Create Specialization Table
CREATE TABLE specialzation (
ids INT NOT NULL,
department VARCHAR (20) NOT NULL,
college_id INT references college(idc),
PRIMARY KEY (ids)
);
-- Add forein keys and relation
ALTER TABLE specialzation
ADD FOREIGN KEY (college_id) REFERENCES college (idc);
-- Inserting Sample Data
INSERT INTO college VALUES(1,'FCI');
INSERT INTO college VALUES(2,'ENG');
INSERT INTO college VALUES(3,'BIO');
INSERT INTO specialzation VALUES(1,'CS',1);
INSERT INTO specialzation VALUES(2,'SCI',2);
INSERT INTO specialzation VALUES(3,'IS',1);
INSERT INTO student VALUES(1,'Ahmed',20,'Cairo','M',3.3,1,1);
INSERT INTO student VALUES(2,'Ali',19,'Cairo','M',3.7,1,2);
INSERT INTO student VALUES(3,'Rania',19,'Mansoura','F',2.3,2,1);
INSERT INTO student VALUES(4,'Saad',21,'Giza','F',3.1,1,2);
select * from student;