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

Assignment

The document outlines the SQL commands for creating a university database named 'university_ass1' with various tables including department, classroom, instructor, student, advisor, course, prereq, time_slot2, section, takes, and teaches. It includes the definition of each table, their constraints, and sample data insertion. Additionally, it demonstrates the relationships between the tables through foreign keys.

Uploaded by

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

Assignment

The document outlines the SQL commands for creating a university database named 'university_ass1' with various tables including department, classroom, instructor, student, advisor, course, prereq, time_slot2, section, takes, and teaches. It includes the definition of each table, their constraints, and sample data insertion. Additionally, it demonstrates the relationships between the tables through foreign keys.

Uploaded by

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

create database university_ass1;

go
use university_ass1;
go
create table department(
dept_name nchar(25),
building varchar(5),
budget int,

constraint pk primary key (dept_name)


);
insert into department values('ECE','SAC','10000');
insert into department values('PHARMACY','NAC','10000');
insert into department values('BIOLOGY','SAC','10000');
SELECT * FROM department;

create table classroom(


building varchar(5),
room_no int,
capacity tinyint,
constraint pk1 primary key(building,room_no)

);
insert into classroom values('NAC','150','40');
insert into classroom values('SAC','160','40');
SELECT * FROM classroom;

create table instructor(


id char(8) primary key,
Name_ varchar(150),
dept_name nchar(25),
salary int,
constraint fk foreign key (dept_name)
references department (dept_name)
);

insert into instructor values ('213','Akash','BIOLOGY','10000');


insert into instructor values ('214','Bkash','ECE','10000');
insert into instructor values ('215','Tkash','PHARMACY','10000');

SELECT * FROM instructor;

create table student(


id char(8),
Name_ varchar(150),
dept_name nchar(25) foreign key references department,
tot_credit tinyint,
constraint pk2 primary key (id)
);
insert into student values ('123','Alvi','ECE','120');
insert into student values ('124','Shihab','PHARMACY','123');
insert into student values ('125','Samir','BIOLOGY','125');

SELECT * FROM student;

create table advisor(


s_id char(8) primary key,
i_id char(8) foreign key references instructor ,
foreign key (s_id) references student
);
insert into advisor values ('123','213');
insert into advisor values ('124','214');
insert into advisor values ('125','215');

select * FROM advisor;

create table course(


course_id int constraint pk4 primary key,
title varchar(100),
dept_name nchar(25),
credits tinyint,
constraint fk3 foreign key (dept_name)
references department (dept_name)

);
insert into course values ('880','BIOCHEMIST','PHARMACY','3');
insert into course values ('881','COMPUTING','ECE','3');
insert into course values ('882','BODY','BIOLOGY','3');

SELECT * FROM course;

create table prereq(


course_id int ,
prereq_id int ,
constraint pk7 primary key (course_id,prereq_id),
constraint fk8 foreign key (course_id)
references course (course_id),
constraint fk9 foreign key (prereq_id)
references course (course_id)

);
insert into prereq values('880','880');
insert into prereq values('881','882');
insert into prereq values('882','881');

SELECT * FROM prereq;

create table time_slot(

time_slot_id varchar(100) ,
day_ int,
start_time varchar(50),
end_time varchar(50),
constraint pk34 primary key (time_slot_id),

);
drop table time_slot;

create table time_slot2(

time_slot_id varchar(100) ,
day_ int,
start_time varchar(50),
end_time varchar(50),
constraint pk34 primary key (time_slot_id)
)
insert into time_slot2 values ('as12','10','10:00 pm','12;00 pm');
insert into time_slot2 values ('as13','10','11:00 pm','12;00 pm');

SELECT * FROM time_slot2;

create table section(


course_id int ,
sec_id int,
semester tinyint,
year_ tinyint,
building varchar(5) ,
room_no int ,
time_slot_id varchar(100)

constraint pk10 primary key (course_id,sec_id,semester,year_),


constraint fk10 foreign key(building,room_no)
references classroom (building,room_no),

constraint fk12 foreign key (course_id)


references course (course_id),

constraint fk14 foreign key (time_slot_id)


references time_slot2 (time_slot_id)

);

create table takes(


id char(8),
course_id int,
sec_id int,
semester tinyint,
year_ tinyint,
grade varchar(10),

constraint pk456 primary key (id,course_id,sec_id,semester,year_),


constraint fk789 foreign key (course_id,sec_id,semester,year_)
references section (course_id,sec_id,semester,year_),

constraint fk456 foreign key (id)


references student (id)

create table teaches(


id char(8),
course_id int,
sec_id int,
semester tinyint,
year_ tinyint,

constraint fk781 foreign key (course_id,sec_id,semester,year_)


references section (course_id,sec_id,semester,year_),

constraint fk67890 foreign key (id)


references instructor (id)
)

You might also like