Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Prac cal 6

-- Integrity And Referen al Integrity Constraint

1)create table classroom:

create table classroom (building varchar (15),

room_no varchar (7),

capacity numeric (4,0),

primary key (building, room_no));

2) create table department:

create table department (dept_name varchar (20),

building varchar (15),

budget numeric (12,2) check (budget > 0), #checks if the budget is >0

primary key (dept_name));

3) create table course :p

create table course (course_id varchar (8),

tle varchar (50),

dept_name varchar (20),

credits numeric (2,0) check (credits > 0),# the credits must be > 0 TO INSERT the values into the
table

primary key (course_id),

foreign key (dept_name) references department on delete cascade on update cascade);

since on delete cascade and on update cascade is used if any changes done to parent row all child
row will updated successfully.

4) create table instructor:

create table instructor (ID varchar (5), name varchar (20) not null,

dept_name varchar (20),

salary numeric (8,2),


check (salary > 29000),# checks if the salary is > 0 otherwise gives error

primary key (ID),

foreign key (dept_name) references department on delete cascade on update cascade);

5)create table sec on :

create table sec on (course_id varchar (8),

sec_id varchar (8),

semester varchar (6),

check (semester in (1,2)),

year numeric (4,0),

check (year > 1759 and year < 2100), # Integrity constraint defined . fro range of the year defined

building varchar (15),

room_no varchar (7),

me_slot_id varchar (4),

primary key (course_id, sec_id, semester, year),

foreign key (course_id) references course,

foreign key (building, room_no) references classroom);

You might also like