Lab 06 DB
Lab 06 DB
Class (cname: char(40), meets_at: char(20), room: char(10), fid: integer | fid REFS Faculty.fid)
Enrolled (snum: integer, cname: char(40) | snum REFS student.snum, cname REFS class.name)
The University schema is given in the figure above. Using this schema perform the following
task:
Task: Create University database and the corresponding tables/relations in the University
schema using the DDL commands. Ensure only the following constraints are specified during the
table creation time:
a. Primary Key
b. Foreign Key
c. Not Null
d. Unique
PK values are given in the figure. sname attribute should not be null while deptid
should always be unique. Assign valid names to all the constraints.
Deliverables
Save all queries and their results in the word document that you are executing. Upload this
document to LMS.
Database Creation:
create database school;
use school;
show databases:
Table Creation:
Student Table:
create table student(
snum int,
sname char(30) NOT NULL,
major char(25),
level char(2),
CONSTRAINT s_number
PRIMARY KEY (snum)
);
desc table;
Faculty Table:
create table faculty (
fid int,
fname char(30),
deptid int UNIQUE,
CONSTRAINT faculty_id
PRIMARY KEY (fid)
);
desc faculty;
Class Table:
create table class (
cname char(40),
meets_at char(20),
room char(10),
fid integer,
CONSTRAINT f_id
FOREIGN KEY (fid) REFERENCES faculty (fid),
CONSTRAINT f_id
PRIMARY KEY (cname)
);
Enrolled Table:
create table enrolled (
snum int,
cname char(40),
CONSTRAINT s_num_fk1
FOREIGN KEY (snum) REFERENCES student (snum),
CONSTRAINT c_name_fk2
FOREIGN KEY (cname) REFERENCES class (cname)
);
desc enrolled;