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

Practical 6 - Dbms

The document describes creating tables in a database to represent classes, departments, courses, instructors, and sections while applying integrity constraints. Tables are created for classroom, department, course, instructor, and section with attributes like building, room number, name, credits, salary, semester, and year. Primary keys are defined and foreign keys are added to link the tables together with references to other tables, enforcing integrity. Checks are added to ensure values meet constraints, like salaries above $29k and years from 1759 to 2100.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views

Practical 6 - Dbms

The document describes creating tables in a database to represent classes, departments, courses, instructors, and sections while applying integrity constraints. Tables are created for classroom, department, course, instructor, and section with attributes like building, room number, name, credits, salary, semester, and year. Primary keys are defined and foreign keys are added to link the tables together with references to other tables, enforcing integrity. Checks are added to ensure values meet constraints, like salaries above $29k and years from 1759 to 2100.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 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