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

Database Managment System

The document describes a student-course database schema for a college. It provides the table structures for student, course, and admission tables along with sample data and queries to retrieve information from the tables. The queries return student names based on various criteria like course enrolled, name starting with a letter, date of birth etc.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Database Managment System

The document describes a student-course database schema for a college. It provides the table structures for student, course, and admission tables along with sample data and queries to retrieve information from the tables. The queries return student names based on various criteria like course enrolled, name starting with a letter, date of birth etc.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 18

SHAHEED RAJGURU COLLEGE OF APPLIED SCIENCES

FOR WOMEN
(UNIVERSITY OF DELHI)

Database Management system


(Generic Elective-3)

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

Char(6) Char(6) Date

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 :-

Inserting data in admission table-


CODE :- insert into admission values('201','C01','2022-10-14');
OUTPUT :-

Inserting data in student table-


CODE :- insert into student values('201','S01','C01','2003-12-24');

● Retrieve names of students enrolled in any course.


CODE :- select rollno,sname from student where cid is not null;
● Retrieve names of students enrolled in at least one part time course.
CODE :- select sname from student, course where student.cid=course.cid and ctype like '%part
%'; OUTPUT :-

● Retrieve students' names starting with letter ‘A’.


CODE :- select sname from student where sname like 'a%';
OUTPUT :-

● Retrieve students' details studying in courses ‘computer science’ or ‘chemistry’.


CODE :- select rollno,sname from student,course where student.cid=course.cid and
(cname='BSc CS' OR cname='BSc Chemistry');
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;

● Update student table for modifying a student name.


update student set sname= 'soumili' where rollno='201';

● 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 youngest student enrolled in course ‘BSc(P)CS’


select sname from student where dob=(select max((dob)) from student);
● Find the name of most popular society (on the basis of enrolled students)
select course.cname, count(*) as numStudents from course inner join admission a on
course.cid=a.cid where course.ctype='part'group by course.cname order by numStudents
DESC limit 1;

● Find the name of two popular part time courses (on the basis of enrolled students)

select course.cname, count(*) as numStudents from course inner join admission a on


course.cid=a.cid where course.ctype='part'group by course.cname order by numStudents
DESC limit 2;

● 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%';

● Find course names in which more than 3 students took admission

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';

● Display the enrolled student for each course.

select cname , count(rollno) as enrolled_student from course , student where course.cid =


student.cid group by course.cid;

● Display the vacant seats for each course


select cname, tseats - count(*) as vacantseats from course left join admission on course.cid =
admission.cid group by course.cid;

● Increment Total Seats of each course by 20%


update course set tseats=1.20*tseats;

● Add enrolment fees paid (‘yes’/’No’) field in the enrolment table.


alter table admission add column fee_paid varchar(5);

● Update the date of admission for all the courses by 1 year.


update admission set doadm=date_add(doadm,interval 1 year);
● Create a view to keep track of course names with total number of students enrolled in
it.
create view CourseEnrollment as select cname,count(*) as numenrolled from course inner join
admission on course.cid=admission.cid group by cname;

● 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.’.

select count(*) as NumCourses from course where cname like 'BSc%science%';

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

Suppliers (SNo, Sname, Status, SCity)

Parts(Pno, Pname, Colour, Weight, City)

Project(Jno, Jname, Jcity)

Shipment(Sno, Pno, Jno, Quantity)

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);

create table shipment(Sno varchar(5), Pno varchar(5),Jno varchar(5),Quantity int,primary


key(Sno,Pno,Jno), foreign key(Sno) references suppliers(Sno) on delete cascade on update
cascade, foreign key(Pno) references parts(Pno) on delete cascade on update cascade, foreign
key(Jno) references project(Jno) on delete cascade on update cascade);

Inserting data in Parts table-


insert into parts values('P5','drill','black',5,'chennai');

Inserting data in Suppliers table-


insert into suppliers values('S5','ROHAN',28,'madras');
Inserting data in Project table-
insert into project values('J1','5G','chennai');

Inserting data in Shipment table-


insert into shipment values('S1','P4','J3',300);

● 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.

select*from shipment where quantity >= 300 and quantity <=700;

● 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;

● Update the city of supplier S1 to “Delhi”.

update suppliers set scity = 'delhi' where sno = 'S1';

● Get part numbers for parts supplied by a supplier in Allahabad to a project in Chennai.

select pno from suppliers , project,shipment where suppliers.sno = shipment.sno and


project.jno=shipment.jno and scity = 'allahabad' and jcity ='chennai';

● Find the names of all parts whose color starts with the letter b.

select pname from parts where colour like 'b%';


● Change the datatype of the weight attribute in the Parts table from int to float.

alter table parts modify column weight float;

● Find the number of parts of each color.

select colour , count(pno) from parts group by colour;

● 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';

● Delete all the projects which are located in Madras.

delete from project where jcity = 'madras';

● 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';

● Add column SDate in shipment table.

alter table shipment add sdate date;

● 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;

● Modify data type of any attribute of table shipment.

alter table shipment modify quantity float;

You might also like