0% found this document useful (0 votes)
14 views

Lab 06 DB

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Lab 06 DB

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Department of Computing

CS220: Database Systems

Class: Fall 2024


Lab 06: DDL and Constraints

Date: October 14, 2024


Time: 10:00-12:50/ 02:00-04:50
Instructor: Dr Shah Khalid/ Dr. Bilal Ali

Lab Engineer: Ms. Ayesha Asif

Name: Ushba Fatima


Class: BESE 14B
CMS: 467212
Lab Task
Schema to be implemented:

Student (snum: integer, sname: char(30), major: char(25), level: char(2))

Faculty (fid: integer, fname: char(30), deptid: integer)

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)

Table Name Primary Key Foreign Key Reference Table


Student Snum
Faculty fid
Class cname fid faculty
Enrolled snum, cname Student, Class

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;

You might also like