MCA Dbms Lab Manual Full
MCA Dbms Lab Manual Full
Belgaum, Karnataka
DATABASE LABORATORY
LABORATORY MANUAL
16MCA28
II SEMESTER - 2017
Prepared By:
Nagesh B S
Asst. Prof.
Dept. of MCA
RNSIT
Phone:9844032238
Department of MCA
ESTD: 2001
An Institution with a difference
BRANCH
Branchid Branchname HOD
STUDENT
USN Name Address Branchid sem
BOOK
Bookid Bookname Authorid Publisher Branchid
AUTHOR
Authorid Authorname Country age
BORROW
USN Bookid Borrowed_Date
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);
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
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 N
gender PROJECT
plocation
age address
No_of_hours pno
pname
Nagesh B S, Asst. Prof., Dept. of MCA, RNSIT, Bengaluru phone:9844032238
SQL> create table employee(eid int primary key,
ename varchar(10),
address varchar(10),
supeid int,
dno int);
EID PHNO
---------- ----------
3 9025678934
4 9807654323
5 8907654323
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
AGE KILOMETERS
COUNTRY
HISTORY
STATE
VDATE
TOURIST M N TOURIST_PLACE
VISITS
TID TNAME
TPID TP_NAME
desc tourist_place;
Name Null? Type
----------------------------------------- -------- ---------------------
TPID NOT NULL NUMBER
HISTORY VARCHAR2(20)
KILOMETERS NUMBER
STATE VARCHAR2(20)
TPNAME VARCHAR2(20)
desc tourist;
Name Null? Type
----------------------------------------- -------- ---------------------
TID NOT NULL NUMBER
COUNTRY VARCHAR2(20)
AGE NUMBER
TNAME VARCHAR2(20)
desc visits;
Name Null? Type
----------------------------------------- -------- ---------------------
TPID NOT NULL NUMBER
TID NOT NULL NUMBER
VDATE DATE
desc email;
Name Null? Type
----------------------------------------- -------- ---------------------
TID NUMBER
EMAIL VARCHAR2(20)
1 row created.
1 row created.
1 row created.
1 row created.
STATE
--------------------
karnataka
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='karnataka'
group by tid having count(state) in (select count(state ) from
tourist_place where state='karnataka') );
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) );
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));
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);
Query 2:
select csstate from constituency group by csstate having count(csstate)
in (select max(count(csstate)) from constituency group by csstate);
CSSTATE
--------------------
karnataka
query 3:
Procedure created.
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.