DBMS Lab Manual - Amc
DBMS Lab Manual - Amc
MMCL106(A)
I SEMESTER – 2024 – 2025
Department of MCA
Program 1
Create the following tables with properly specifying Primary keys, Foreign
keys and solve the following queries.
BRANCH(Branchid,Branchname,HOD)
STUDENT(USN,Name,Address,Branchid,sem)
BOOK(Bookid,Bookname,Authorid,Publisher,Branchid)
AUTHOR(Authorid,AuthoAMame,Country,age)
BORROW(USN,Bookid,Borrowed_Date)
Queries:
1 List the details of Students who are all Studying in 2nd sem MCA.
2 List the students who are not borrowed any books.
3 Display the USN, Student name, Branch_name, Book_name, Author_name ,
Books_Borrowed_Date of 2nd sem MCA Students who borrowed books.
4 Display the number of books written by each Author.
5 Display the student details who borrowed more than two books.
6 Display the student details who borrowed books of more than one Author.
7 Display the Book names in descending order of their names.
8 List the details of students who borrowed the books which are all published by
the same Publisher.
BRANCH
Branchid Branchname HOD
STUDENT
USN Name Address Branchid sem
BOOK
Bookid Bookname Authorid Publisher Branchid
AUTHOR
Authorid AuthoAMame Country age
BORROW
USN Bookid Borrowed_Date
1 mca npk
2 mba bojanna
3 cse gtr
4 ise sudhamani
5 electrical sumathi
Query 1.
select * from student where sem=2 and branchid in
(select branchid from branch where bname='mca')
Query 2.
select * from student where usn not in (select usn from borrow);
Query 3.
select student.usn ,student.name,branch.bname, book.bname, aname,
borrowdate from student , branch, book, author, borrow where
student.usn=borrow.usn and borrow.bookid=book.bookid and
book.authorid =author.authorid and student.branchid=branch.branchid
and student.sem=2 and branch.bname='mca';
Query 4.
select count(*) , authorid from book group by authorid;
COUNT(*) AUTHORID
1 123
1 125
1 124
1 126
1 127
Query 5.
select * from student where usn in ( select usn from borrow group
by usn having count(usn) >=2);
Query 6.
select * from student s where exists (select br.usn from borrow br
join book bk on br.bookid=bk.bookid where br.usn=s.usn group by usn
having count(distinct authorid)>1);
Query 7.
select bname from book order by bname desc;
BNAME
unix
oops
dbms
cprog
c prog
Query 8.
select * from student s where exists (select usn , publisher from
borrow join book on borrow.bookid=book.bookid where s.usn=borrow.usn
group by usn having count(distinct publisher)=1);
Program 2
Design an ER-diagram for the following scenario, Convert the same into a relational
model and
then solve the following queries.
Consider a Cricket TouAMament “ABC CUP” organized by an organization. In the
touAMament
there
are many teams are contesting each having a Teamid,Team_Name, City, a coach. Each team is
uniquely identified by using Teamid. A team can have many Players and a captain. Each player
is uniquely identified by Playerid, having a Name, and multiple phone numbers,age. A player
represents only one team. There are many Stadiums to conduct matches. Each stadium is
identified using Stadiumid, having a stadium_name,Address ( involves
city,area_name,pincode).A team can play many matches. Each match played between the two
teams in the scheduled date and time in the predefined Stadium. Each match is identified
uniquely by using Matchid. Each match won by any of the one team that also wants to record in
the database. For each match man_of_the match award given to a player.
Queries:
1 Display the youngest player (in terms of age) Name, Team name , age in which he belongs of
the touAMament.
2 List the details of the stadium where the maximum number of matches were played.
3 List the details of the player who is not a captain but got the man_of _match award at least in
two matches.
4 Display the Team details who won the maximum matches.
5 Display the team name where all its won matches played in the same stadium.
1 sachin 33 123
2 dravid 32 124
3 dhoni 30 124
4 raina 30 125
5 kohli 23 126
1 998882928
2 877563733
2 988928822
3 877366383
Query 1 :
Select pname, tname, age from player p, team t where
p.tid=t.tid and age =(select min(age) from player);
PNAME TNAME AGE
kohli daredevils 23
Query 2:
select * from stadium where sid in
(select sid from match group by sid having count(sid) =
(select max(count(sid)) from match group by sid))
Query 3:
select * from player where pid not in ( select captain_pid from
team) and pid in (select man_of_match from match group by
man_of_match having count(man_of_match)=2);
PID PNAME AGE TID
5 kohli 23 126
Query 4:
select * from team where tid in (select winning_team_id from
match group by winning_team_id having count(winning_team_id)=
(select max(count(winning_team_id))from match group by
winning_team_id))
Query 5
select tname from team where tid in (
select winning_team_id from match group
by(winning_team_id,sid)
having count(*) in (select count(winning_team_id)
from match group by winning_team_id))
TNAME
rcb
Program 3
Consider the following Scenario and design an ER-Diagram, map the designed ER-
diagram into a Relational model. Consider an organization “ABC” having many employees.
An employee works for one department. Each employee identified by using Empid, having
Name, address ( described as House_no, city, district, state, pin code) and more than one phone
numbers. Department identified by using Dno, having Dname, Dlocation. Each Department
having a manager . Each department having many employees. There are many Projects , each
project is controlled by the department. Each Project uniquely identified by Pno, having
Project_name, Project_location. An employee works on many Projects. Number of hours per
week worked on each project by an Employee also needs to be recorded in the database . A
project is worked by many employees. Each employee supervised by the supervisor. Employee
having many dependents. Dependents having the dependent_name, gender, age, address.
Dependents are identified by Empid.
T1(Empid, Emp_Name,city, district, state, pin_code, phoneno, Dno,Dname,Dlocation,
Dept_mgr_id,Pno,Project_name, Project_location, Number_of_Hours,Supervisor_Empid,
Dependent_name, gender, address) ,Deduce the above Relation T1 into the 3NF and then
solve the following queries.
Queries:
1. Display the details of the employees who are working on both the projects having project_no
5 and 10.
2. Display the details of employees having atleast two dependents.
3. Display the project name on which more number of employees are working.
4. Retrieve the employees who do not have any dependents.
5. Display the Employee details whose total number of hours per week working on various
projects is maximum than all other employees.
6. create a view to display the number of employees working in each department.
dno dlocation
dname
SUPERVISES DEPARTMENT
1 N
ename 1 WORKSFOR
M
1
eid EMPLOYEE 1
1
1 MANAGES
address CONTROL
1
HAS
name
N WORKSON 1
M
N
DEPENDENT
gender PROJECT
plocation
age address
No_of_hours pno
pname
DBMS LAB(MMCL106(A)) 2024-25
priya f 20 mumbai 1
divya f 19 blore 2
priyanka f 18 madurai 3
sarvan m 24 delhi 3
jothi f 40 madurai 5
lakshmi f 23 udupi 1
1 111 5
3 222 4
2 333 7
4 111 10
5 444 20
1 5 4
1 10 8
EID PHNO
3 9025678934
4 9807654323
5 8907654323
2 7896897654
1 9087654321
Query 3. select pname from project where pno in(select pno from
empproj group by pno having count(pno)=(select max(count(pno)) from
empproj group by pno))
PNAME
student
Query 4. select * from employee where eid not in (select eid from
dependent);
Query 5. select * from employee where eid in(select eid from empproj
group by eid having sum(hpw)= 2 (select max(sum(hpw)) from empproj
group by eid));
Query 6.
create view empcount(dno,no_of_emp) as select dno,count(dno) from
employeee group by dno;
DNO NO_OF_EMP
200 2
300 1
400 1
500 1
Program 4
Design an ER-diagram for the following scenario, Convert the same into a relational model,
normalize Relations into a suitable Normal form and then solve the following queries. A
country can have many Tourist places . Each Tourist place is identified by using
tourist_place_id, having a name, belongs to a state, Number of kilometers away from the capital
city of that state,history. There are many Tourists visits tourist places every year. Each tourist is
identified uniquely by using Tourist_id, having a Name, age, Country and multiple emailids. A
tourist visits many Tourist places, it is also required to record the visted_date in the database. A
tourist can visit aTourist place many times at different dates. A Tourist place can be visited by
many tourists either inthe same date or at different dates.
Queries:
1 List the state name which is having maximum number of tourist places.
2 List details of Tourist place where maximum number of tourists visited.
3 List the details of tourists visited all tourist places of the state “KAAMATAKA”.
4 Display the details of the tourists visited at least one tourist place of the state, but visited all
states tourist places.
5 Display the details of the tourist place visited by the tourists of all country.
AGE KILOMETERS
COUNTRY
HISTORY
STATE
VDATE
TOURIST M N TOURIST_PLACE
VISITS
TID TNAME
TPID TP_NAME
desc tourist_place;
Name Null? Type
desc tourist;
Name Null? Type
desc visits;
Name Null? Type
desc email;
Name Null? Type
TID NUMBER
EMAIL VARCHAR2(20)
1 row created.
1 row created.
22 india 34 prakash
23 orissa 28 bhanu
24 india 30 nagesh
1 row created.
12 23 13-NOV-14
11 24 24-JUN-13
13 22 25-SEP-11
11 23 23-FEB-10
13 23 12-JAN-10
14 24 10-JAN-17
1 row created.
23 [email protected]
22 [email protected]
24 [email protected]
Query 1:
STATE
kaAMataka
query 2:
select * from tourist_place where tpid in (select tpid from visits group
by tpid having count(tpid)= (select max(count(tpid)) from visits group by
tpid));
query 3:
select * from tourist t where t.tid in
(select tid from visits join tourist_place on
visits.tpid=tourist_place.tpid where state='kaAMataka'
group by tid having count(state) in (select count(state ) from
tourist_place where state='kaAMataka') );
24 india 30 nagesh
query 4:
select * from tourist t where t.tid in (select tid from visits join
tourist_place on visits.tpid=tourist_place.tpid
group by tid having count(distinct state)
in (select count(distinct state ) from tourist_place) );
23 orissa 28 bhanu
query 5:
select * from tourist_place where tpid in (
select tpid from visits join tourist on visits.tid=tourist.tid
group by tpid having count(distinct country)=
(select count(distinct country) from tourist));
Program 5
Design an ER-diagram for the following scenario, Convert the same into a relational model,
normalize Relations into a suitable Normal form and then solve the following queries.
A country wants to conduct an election for the parliament. A country having many constituencies.
Each constituency is identified uniquely by Constituency_id, having the Name, belongs to a
state, Number_of_voters. A constituency can have many voters. Each voter is uniquely identified
by using Voter_id, having the Name, age, address (involves Houseno, city, state, pincode). Each
voter belongs to only one constituency. There are many candidates contesting in the election.
Each candidates are uniquely identified by using candidate_id, having Name, phone_no, age,
state. A candidate belongs to only one party. There are many parties. Each party is uniquely
identified by using Party_id, having Party_Name, Party_symbol. A candidate can contest from
many constituencies under a same party. A party can have many candidates contesting from
different constituencies. No constituency having the candidates from the same party. A
constituency can have many contesting candidates belongs to different parties. Each voter votes
only one candidate of his/her constituency.
Queries:
1 List the details of the candidates who are contesting from more than one constituencies which
are belongs to different states.
2 Display the state name having maximum number of constituencies.
3 Create a stored procedure to insert the tuple into the voter table by checking the voter age.
If voter’s age is at least 18 years old, then insert the tuple into the voter else display the
“Not an eligible voter msg” .
4 Create a stored procedure to display the number_of_voters in the specified constituency.
Where the constituency name is passed as an argument to the stored procedure.
5 Create a TRIGGER to UPDATE the count of “ Number_of_voters” of the respective
constituency in “CONSTITUENCY” table , AFTER inserting a tuple into the “VOTERS”
table.
---
121 9538904626 23 kerala raksha 876
122 9740777502 24 kaAMataka veena 877
111 122
222 121
222 122
Query 1:
select * from candidates where cand_id in (select cand_id from
contest
join constituency on contest.cons_id=constituency.cons_id
group by cand_id having count(distinct(csstate))>1);
---
122 9740777502 24 kaAMataka veena
877
Query 2:
select csstate from constituency group by csstate having
count(csstate)
in (select max(count(csstate)) from constituency group by csstate);
CSSTATE
kaAMataka
query 3:
BEGIN
if age>18 then
insert into voter(vid,vage) values (id,age);
else
dbms_output.put_line('age should be high');
end if;
end agechecking;
/
Procedure created.
query 4:
create or replace procedure display_count
(
const_id number
)
as
vid constituency.cons_id % type;
begin
select no_of_voters into vid from constituency where cons_id =
const_id
and rownum = 1;
dbms_output.put_line ( 'total voters are: ' || vid);
end;
/
Procedure created.
SQL> select * from constituency;
Query 5:
create or replace trigger count
after insert on voter
for each row
begin
update constituency
set no_of_voters = no_of_voters + 1
where cons_id=:new.cons_id;
end count;
/
Trigger created.
1 row created.