0% found this document useful (0 votes)
67 views10 pages

Tutorial - 6 ID: 190030562 Name: G Likhith Chowdary University Online Examination Scheduling System)

The document provides solutions to 10 SQL queries related to an online university examination scheduling system database. The queries create tables, insert sample data, display counts of students enrolled in courses, show details of proctors and squads, update exam dates, and provide counts of students enrolled in courses by department.

Uploaded by

likhith chowdary
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
67 views10 pages

Tutorial - 6 ID: 190030562 Name: G Likhith Chowdary University Online Examination Scheduling System)

The document provides solutions to 10 SQL queries related to an online university examination scheduling system database. The queries create tables, insert sample data, display counts of students enrolled in courses, show details of proctors and squads, update exam dates, and provide counts of students enrolled in courses by department.

Uploaded by

likhith chowdary
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Tutorial – 6

ID: 190030562

NAME : G LIKHITH CHOWDARY

Implement the following SQL Queries on Case study 2 ( University Online Examination
Scheduling system)

1) Create all the necessary tables with all the required constraints
Solution:

create database online_university_exams_190030562;

use online_university_exams_190030562;

CREATE TABLE student (

SID INT NOT NULL,

Name VARCHAR(100),

Address VARCHAR(100),

phone INT NOT NULL,

emgPN INT,

PRIMARY KEY (SID)

);

CREATE TABLE course (

CID INT NOT NULL AUTO_INCREMENT,

Name VARCHAR(100),

Coursecode VARCHAR(100),

dept VARCHAR(50),

PRIMARY KEY (CID)

);

create table cregd


(

dept varchar(50) not null check (dept='cse'or dept='ece'),

sid int not null,

foreign key(sid) references student(sid)

);

create table creg

sno int not null auto_increment,

SID int not null,

cid int not null,

primary key(sno),

foreign key(SID) references cregd(SID),

foreign key(CID) references Course(CID)

);

create table fac

FID int not null,

Name varchar(100),Address varchar(100),

phone int not null,

emgPN int,

primary key(FID)

);

create table examclass

sno int not null auto_increment,


CLID int not null,

St int not null,

sid int not null,

primary key (sno),

foreign key(SID) references student(SID)

);

create table examf

FID int not null,

staffrole varchar(20) not null check (staffrole='proctor' or staffrole='sqaud')

);

create table examt

t int not null auto_increment,

CID int not null,

examtype varchar(20) not null check (examtype='detained'or examtype='regular' or


examtype='supply'),dte date not null,FID INT NOT NULL,primary key(t),foreign key (FID)
references fac(FID)

);
2) Insert appropriate data into the tables
Solution:

insert into student(sid,name,address,phone,emgPN)

values(2,'','vjy',123456,111213),

(3,'ajay','vjy',15689944,264445);

insert into cregd(dept,sid)

values ('ece',2),('ece',3);

insert into student(sid,name,address,phone,emgPN)

value(1,'tharun','vjy',123456,111213);

insert into cregd(dept,sid)

values('cse',1);

insert into course(name,coursecode,dept)

value('dbms','19sc1230','cse'),

('os','19cs1200','cse'),

('qp','19sc166','ece');

insert into creg(SID,CID)

value(1,1),

(1,2);

insert into fac(FID,name,address,phone,emgPN)

values(3012,'raj','vjy',13456,1113),

(3013,'kavin','vjy',15515,111254);

insert into examclass(CLID,st,sid)

value(102,24,1);

insert into examf(FID,staffrole)


values(3012,'proctor'),

(3013,'sqaud');

insert into examt(CID,examtype,DTE,Fid)

values(1,'regular','2020-09-08',3012),

(1,'supply','2020-09-08',3012),

(1,'detained','2020-09-08',3012),

(1,'regular','2020-09-08',3013),

(1,'supply','2020-09-08',3013),

(1,'detained','2020-09-08',3013),

(2,'regular','2020-09-09',3013);
3) Display the number of students enrolled for exam ‘DBMS’
Solution: select count(*) as no_stud_dbms from creg where cid=(select cid from course where
name='dbms');

4) Show the details of proctors having duty more than 3 times


Solution: select * from fac where fid=( select fid from examt group by fid having count(*)>=3) ;
5) Get the details of faculty working as squad
Solution: select * from fac where fid=(select fid from examf where staffrole='sqaud');

6) Display the details of proctors and squad for exam ‘DBMS’


Solution: select * from fac where fid=(select fid from course where name='dbms');
7) Show the number of rooms allotted for each course on ‘Tuesday’
Solution: select * from examt where weekday(dte)=1;

8) Update the exam date of ‘OS’ which is postponed to 2 days after the scheduled date
Solution: update examt set dte='2020-09-11' where cid=1;(previous date is 2020-09-09)
9) Give the no. of students enrolled in each course department-wise
Solution: select dept,count(*) as no_reg from cregd group by dept ;

10) Display the course details where the enrolled students are greater than the enrolled students in
DBMS
Solution:

select dept,count(*) as no_reg from cregd group by dept having count(*)>(select count(*) from
cregd where dept='cse');

You might also like