Database Managment System
Database Managment System
FOR WOMEN
(UNIVERSITY OF DELHI)
PRACTICLE FILE
NAME:- Archita Yadav
DEPARTMENT: - ELECTRONICS
EXAM ROLL NO. : - 22066558002
PRACTICLE 1:- Create and use the following student-course database schema for
a college to answer the given queries using the standalone SQL editor.
STUDEN Student
Roll No Course ID DOB
T Name
Varchar(10
Char(6) Varchar(20) Date
)
Course Teacher
COURS Cours Total Duratio
CID in-
E Name e Type Seats n
charge
Char(6 Varchar(20 Char(8 Varchar(15 Unsigne Unsigne
) ) ) ) d int d int
Roll Date of
ADMISSION CID
No Admission
Here, Roll No (ADMISSION) and CID (ADMISSION) are foreign keys. Note that
course type may have two values viz. Fulltime and Part-time and a student may
enroll in any number of courses.
CODE :- create table course(cid char(6) primary key,cname varchar(20) NOT NULL, ctype
char(6),tic varchar(15) NOT NULL,tseats int,duration int);
desc course;
create table Student(Rollno char(6) Primary key,Sname varchar(20) not null ,Cid char(6) not
null ,DOB date not null,foreign key(Cid) references course (Cid));
desc student;
create table admission(rollno char(6),cid char(6),doadm date,primary key(rollno,cid),foreign
key(rollno) references student(rollno),foreign key(cid) references course (cid));
desc admission;
OUTPUT :-
Inserting data in course table-
CODE :- insert into course values('C01','BSc Maths','UG','sonal',40,6);
OUTPUT :-
● Retrieve students’ names whose roll no either starts with ‘X’ or ‘Z’ and ends with ‘9’.
CODE :- select sname from student where (rollno like 'X%' OR rollno like 'Z%') and rollno like
'%9';
OUTPUT :-
● Find course details with more than N students enrolled where N is to be input by the
user.
select course.cid,cname,ctype from student, course where student.cid=course.cid group by
course.cid having count(rollno)>=2;
● Find course names in which more than five students have enrolled
select course.cid,cname,ctype from student, course where student.cid=course.cid group by
course.cid having count(rollno)>=5;
● Find the name of two popular part time courses (on the basis of enrolled students)
● the student names who are admitted to full time courses only.
select sname from student , course where student.cid = course.cid and ctype like '%full%';
select cname from course , admission where course.cid = admission.cid group by course.cid
having count(rollno)>=3;
● Find names of all students who took admission to any course and course names in which
at least one student has enrolled.
select sname , cname from student , course where student.cid = course.cid;
● Find course names where teacher-in-charge has ‘Gupta’ as surname and the course is
full time.
select cname from course where tic like '%gupta%' and ctype = 'full';
● Add column Mobile number in student table with default value ‘9999999999’ .
alter table student add column mob_no varchar(10) default '9999999999';
● Find names of students who are born in 2001 and are admitted to at least one part time
course.
select distinct sname from student inner join admission on student.rollno=admission.rollno
inner join course on admission.cid=course.cid where year(dob) = 2001 and ctype='part';
● Count all courses having ‘science’ in the name and starting with the word ‘B.Sc.’.
PRACTICLE 2:- . Create the following tables with appropriate data type for attributes and
integrity constraints on the tables. Enter at least 5 records in each table and answer the
queries given below
CODE - create table suppliers(Sno varchar(5) primary key, Sname varchar(20) NOT NULL,
Status int NOT NULL, Scity varchar(10) NOT NULL);
create table parts(Pno varchar(5) primary key, Pname varchar(10) NOT NULL, Colour
varchar(10) NOT NULL, Weight int NOT NULL, City varchar(10) NOT NULL);
create table project(Jno varchar(5) primary key,Jname varchar(10) NOT NULL, Jcity varchar(10)
NOT NULL);
● Find supplier numbers for suppliers in Mandi with status less than 20.
select sno from suppliers where status> < 20 and scity = 'mandi';
● Find supplier details for suppliers who supply part P2. Display the supplier list in
decreasing order of supplier numbers.
select suppliers.sno , sname , scity from suppliers , shipment where shipment.sno =
suppliers.sno and pno = 'P2' order by sno desc;
● Find suppliers names for suppliers who do not supply part P2.
select sname from suppliers , shipment where shipment.sno = suppliers.sno and pno<>'P2';
● For each shipment get full shipment details, including total shipment weights computed
as Weight*Quantity of corresponding parts.
select sno , parts.pno , jno,quantity,weight, quantity*weight as total_weight from
parts,shipment where parts.pno = shipment.pno;
● Get all the shipments where the quantity is in the range 300 to 750 inclusive.
● Get part numbers for parts that either weigh more than 1Kg or are supplied by suppliers
S2 or both.
select pno from parts where weight > 1 union select pno from shipment where sno = 'S2';
● Get the names of cities that store more than two red parts. Change the column name in
the output to “City-Parts”
select city as city_parts from parts where colour = 'red' group by city having count(pno)>2;
● Get part numbers for parts supplied by a supplier in Allahabad to a project in Chennai.
● Find the names of all parts whose color starts with the letter b.
● Find the names of all the projects which are located in the city Jaipur and in which the
part is supplied by supplier S3.
select jname from project , shipment where project.jno=shipment.jno and jcity = 'jaipur' and
sno = 'S3';
● Find all part-details of parts that are shipped to any project carried out in Mumbai.
select parts.pno , pname , city from project , shipment , parts where project.jno =
shipment.jno and parts.pno = shipment.pno and jcity = 'mumbai';
● Find number of unique projects supplied by supplier S1.
select distinct count(jno) from shipment where sno = 'S1';
● For each supplier which supplies parts to a project, find the total no. of parts supplied by
the supplier.
select count(pno) from shipment group by sno;
● Find all supplier name, part name and project name triples such that the indicated
supplier, part, and project are all located in the same city.
select sname ,pname,jname from suppliers ,parts,project,shipment where suppliers.sno =
shipment.sno and parts.pno = shipment.pno and project.jno = shipment.jno and scity = city
and city = jcity;
● Get the names of cities from where more than three yellow parts are supplied.
select distinct city from parts where colour = 'yellow' group by city having count(pno)>3;
● Find all distinct cities where either supplier is living or parts are shipped from or projects
are carried out.
select scity from suppliers union select jcity from project union select city from parts;
● Find names of cities such that atleast one supplier is living there and atleast one part is
shipped and one project is carried out.
select scity from suppliers intersect select jcity from project intersect select city from parts;