0% found this document useful (0 votes)
559 views66 pages

Practical:-1: QUES1: Using The Following Database

The document provides the schema for a college database including tables for colleges, staff, subjects, and teaching assignments. It also provides SQL statements to: 1. Create the tables with the given specifications and constraints 2. Insert sample data into the tables to solve subsequent queries 3. List the names of teachers teaching computer subjects 4. List the names and cities of all staff working in a particular college 5. Additional queries are provided but not summarized The SQL statements create the tables as specified, then insert sample rows of data into each table. Example queries are provided to select teacher names for computer subjects and staff names and cities for a given college.
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)
559 views66 pages

Practical:-1: QUES1: Using The Following Database

The document provides the schema for a college database including tables for colleges, staff, subjects, and teaching assignments. It also provides SQL statements to: 1. Create the tables with the given specifications and constraints 2. Insert sample data into the tables to solve subsequent queries 3. List the names of teachers teaching computer subjects 4. List the names and cities of all staff working in a particular college 5. Additional queries are provided but not summarized The SQL statements create the tables as specified, then insert sample rows of data into each table. Example queries are provided to select teacher names for computer subjects and staff names and cities for a given college.
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/ 66

PRACTICAL:- 1

QUES1: Using the following database


Colleges (cname, city, address, phone, afdate)
Staffs ( sid, sname, saddress, contacts)
StaffJoins ( sid, cname, dept, DOJ, post, salary)
Teachings ( sid, class, paperid, fsession, tsession)
Subjects ( paperid, subject, paperno, papername)

Write SQL statements for the following : –

a. Create the above tables with the given specifications and constraints.
b. Insert about 10 rows as are appropriate to solve the following queries.
c. List the names of the teachers teaching computer subjects.
d. List the names and cities of all staff working in your college.
e. List the names and cities of all staff working in your college who earn more than 15,000
f. Find the staffs whose names start with ‘M’ or ‘R’ and ends with ‘A’ and/or 7 characters
long.
g. Find the staffs whose date of joining is 2005.
h. Modify the database so that staff N1 now works in C2 College.
i. List the names of subjects, which T1 teaches in this session or all sessions.
j. Find the classes that T1 do not teach at present session.
a. Find the colleges who have most number of staffs.
b. Findthestaffsthatearnahighersalarywhoearngreaterthanaveragesalaryoftheircoll
ege.
c. FindthecollegeswhoseaveragesalaryismorethanaveragesalaryofC2
d. Findthecollegethathasthesmallestpayroll.
e. Findthecollegeswherethetotalsalaryisgreaterthantheaveragesalaryofallcolleges
.

k. Listmaximum,average,minimumsalaryofeachcollege

a. Listthenamesoftheteachers,departmentsteachinginmorethanonedepartment.

b. Acquiredetailsofstaffsbynameinacollegeoreachcollege.

c. FindthenamesofstaffthatearnmorethaneachstaffofC2College.

d. Giveallprincipalsa10%riseinsalaryunlesstheirsalarybecomesgreaterthan20,000i
nsuchcasegive5%rise.

L. Findallstaffthatdonotworkinsamecitiesasthecollegestheywork.

M. Listnamesofemployeesinascendingorderaccordingtosalarywhoareworkinginyourcollegeo
rallcolleges.

1
a. Createaviewhavingfieldssname,cname,dept,DOJ,andpost

b. Createaviewconsistingofcname,averagesalaryandtotalsalaryofallstaffinthatcoll
ege.

c. Selectthecollegeshavinghighestandlowestaveragesalaryusingaboveviews.

d. Listthestaffnamesofadepartmentusingaboveviews.

A)Createtheabovetableswiththegivenspecificationsandconstraints
QUE:-Createtablecolleges(cname,city,address,phone,afdate)

SQL>createtablecolleges(cnamevarchar2(10)primarykey,cityvarchar2(15),addres
svarchar2(15)notNULL,phonenumber(10),afdatedate);

SQL> desccolleges;

QUE:Createtablestaffs(sid,sname,saddress,contacts)

SQL>createtablestaffs(sidvarchar2(5)primarykey,snamevarchar2(15),saddressvarch
ar2(15),contactsnumber(10));

SQL> descstaffs;

QUE:Createtablesubjects(paperid,subjects,paperno,papername)
SQLcreatetablesubjects(paperidvarchar2(5)primarykey,subjectsvarchar2(15)notNULL,
papernovarchar2(5),papernamevarchar2(15)unique);
SQL> descsubjects;

2
QUE:Createtableteachings(sid,class,paperid,fsession,tsession)

SQL
createtableteachings(sidvarchar2(5)referencesstaffs(sid),classvarc
har2(10),paperidvarchar2(5)referencessubjects(paperid),fsessiondate,t
sessiondate);
SQL> descteachings;

QUE:Createtablestaffjoins(sid,cname,dept,doj,post,salary)

SQL>createtablestaffjoins(sidvarchar2(5)referencesstaffs(sid),cnamevarchar2(10)refer
encescolleges(cname),deptvarchar2(10),dojdatenotNULL,postvarchar2(10),sal
arynumber(5));
SQL> descstaffjoins;

B)Insertabout10rowsasareappropriatetosolvethefollowingqueries.
1)Insertrowsintocolleges
SQL>insertintocollegesvalues(‘c1’,’bhilai’,’sec-
6’,8982655645,’12jan1985’);SQL>insertintocollegesvalues(‘c2’,’raipur’,’ashoknagar’,89
82655644,’1jan1980’);SQL>insertintocollegesvalues(‘c3’,’rajnandgao’,’dipaknagar’,898
2655643,
’3mar1981’);
SQL>insertintocollegesvalues(‘c4’,’rajnandgao’,’ashishnagar’,8982655642,’2apr19
91’);

3
SQL>insertintocollegesvalues(‘c5’,’durg’,’padmnabpur’,8982655641,’15jan
1996’);
SQL>insertintocollegesvalues(‘c6’,’durg’,’kalibadi’,8982655640,’15jan1984’);SQL>i
nsertintocollegesvalues(‘c7’,’bhilai’,’sec-
10’,8982655639,’15feb1988’);SQL>insertintocollegesvalues(‘c8’,’bhilai’,’hudco’,898
2655638,’1jul1980’);SQL>insertintocollegesvalues(‘c9’,’bhilai’,’sec-
11’,8982655637,’1mar1979’);SQL>insertintocollegesvalues(‘c10’,’bhilai’,’nehrunagar
’,8982655636,
’10aug1980’);
SQL>Select*fromcolleges;

OUTPUT:-

2)Insertrowsintostaffs.
SQL>insertintostaffsvalues(‘c101’,’ramakrishna’,’bhilai’,8899112233);SQL
>insertintostaffsvalues(‘c102’,’rama’,’bhilai’,8899112232);SQL>insertintost
affsvalues(‘c103’,’mayata’,’raipur’,8899112231);SQL>insertintostaffsvalues(
‘c201’,’t1’,’durg’,8899112230);
SQL>insertintostaffsvalues(‘c202’,’t2’,’durg’,8899112229);SQL>i
nsertintostaffsvalues(‘c301’,’t3’,’durg’,8899112228);SQL>insertint
ostaffsvalues(‘c401’,’n1’,’bhilai’,8899112227);SQL>insertintostaff
svalues(‘c501’,’n2’,’raipur’,8899112226);SQL>insertintostaffsvalu
es(‘c601’,’t5’,’bhilai’,8899112225);SQL>insertintostaffsvalues(‘c7
01’,’t5’,’durg’,8899112224);
SQL> Select*fromstaffs;
OUTPUT:-

4
3)Insertrowsintostaffjoins.
SQL>insertintostaffjoinsvalues(‘c101’,’c3’,’computer’,’1mar2009’,’teacher’,10000);SQ
L>insertintostaffjoinsvalues(‘c102’,’c1’,’maths’,’1apr2009’,’principal’,17000);SQL>ins
ertintostaffjoinsvalues(‘c103’,’c2’,’maths’,’1apr2007’,’teacher’,17000);SQL>insertintost
affjoinsvalues(‘c301’,’c2’,’science’,’1apr2005’,’clerk’,1000);SQL>insertintostaffjoinsva
lues(‘c401’,’c5’,’arts’,’1may2004’,’clerk’,1000);
SQL>insertintostaffjoinsvalues(‘c501’,’c6’,’english’,’1mar2002’,’vprincipal’,12000);SQ
L>insertintostaffjoinsvalues(‘c601’,’c7’,’hindi’,’12apr2007’,’teacher’,10000);SQL>inser
tintostaffjoinsvalues(‘c701’,’c8’,’commerce’,’1mar09’,’teacher’,10000);SQL>insertintos
taffjoinsvalues(‘c601’,’c9’,’maths’,’1aug2009’,’hod’,11000);
SQL>insertintostaffjoinsvalues(‘c501’,’c10’,’hindi’,’1jul2009’,’hod’,11000);
SQL>select*fromstaffjoins;

OUTPUT:-

4)Insertrowsintosubjects.
SQL>insertintosubjectsvalues(‘p1’,’computer’,’101’,’dbms’);SQ
L>insertintosubjectsvalues(‘p2’,’arts’,’102’,’dance’);
SQL>insertintosubjectsvalues(‘p3’,’finearts’,’103’,’sketching’);SQL>i
nsertintosubjectsvalues(‘p4’,’maths’,’104’,’claculus’);SQL>insertintos
ubjectsvalues(‘p5’,’english’,’105’,’foundation’);SQL>insertintosubject
svalues(‘p6’,’economics’,’106’,’statsistics’);SQL>insertintosubjectsval
ues(‘p7’,’businessstd’,’107’,’accounts’);SQL>insertintosubjectsvalues(
‘p8’,’hindi’,’108’,’mainreader’);SQL>insertintosubjectsvalues(‘p9’,’so
cialstd’,’109’,’history’);SQL>insertintosubjectsvalues(‘p10’,’science’,’
110’,’physics’)
SQL> select*fromsubjects;

5
OUTPUT:-

5)Insertrowsintoteachings.
SQL>insertintoteachingsvalues(‘c101’,’bca2’,’p1’,’1jan2007’,’1jan2009’);SQL>i
nsertintoteachingsvalues(‘c102’,’bca2’,’p4’,’1mar2005’,’31mar2009’);SQL>inser
tintoteachingsvalues(‘c201’,’bca1’,’p5’,’1jan2006’,’1jan2009’);SQL>insertintotea
chingsvalues(‘c301’,’bcom2’,’p6’,’1aug2007’,’1aug2009’);SQL>insertintoteachin
gsvalues(‘c401’,’bcom1’,’p7’,’1july2002’,’1july2009’);SQL>insertintoteachingsv
alues(‘c501’,’bcom2’,’p5’,’1sep2003’,’1sep2009’);SQL>insertintoteachingsvalue
s(‘c601’,’bsc1’,’p10’,’1feb2001’,’31mar2009’);SQL>insertintoteachingsvalues(‘c
701’,’bsc2’,’p10’,’1mar2007’,’31mar2009’);SQL>insertintoteachingsvalues(‘c10
3’,’bba2’,’p7’,’1july2004’,’1july2009’);SQL>insertintoteachingsvalues(‘c202’,’b
ba1’,’p2’,’1jan2003’,’1jan2009’);
SQL>select*fromteachings;

OUTPUT:

c)Listthenamesoftheteachersteachingcomputersubject.

SQL>selectsnamefromstaffswheresid=(selectsidfromteachingswherepaperi
d=(selectpaperidfromsubjectswheresubjects='computer'));

OUTPUT:
6
d)Listallthenameandcitiesofallstaffworkinginyourcollege.
SQL>selectsname,saddressfromstaffswheresid=(selectsidfromstaffjoinswhere
cname='c1');

OUTPUT:

e)Listthenamesandcitiesofallstaffworkinginyourcollegewhoearnmorethan15,00
0.
SQL>selectsname,saddressfromstaffswheresid=(selectsidfromstaffjoinswherec
name='c1'andsalary>15000);

OUTPUT:-

f)Findthestaffswhosenamesstartwith‘M’or‘R’andendswith‘A’and/or7characters
long.
SQL> selectsnamefromstaffswheresnamelike'm_____a%'orsnamelike'r%a';

OUTPUT:-

g)Findthestaffswhosedateofjoiningis2005.
SQL>selectsnamefromstaffswheresid=(selectsidfromstaffjoinswhereextract
(yearfromdoj)='2005');

OUTPUT:-

7
h)Modifythedatabasesothatstaffsn1nowworksinc2college.
SQL>updatestaffjoinssetcname='c2'wheresid=(selectsidfromstaffswheresname
='n1');
SQL>select*fromstaffjoins;

OUTPUT:-

i) Listthenameofsubjectswhicht1teachesinthissessionorallsession.

SQL>selectsubjectsfromsubjectswherepaperid=(selectpaperidfromteachingswhere(extract(yea
rfromfsession)='2009'orfsessionisnotNULL)andsid=(selectsidfromstaffswheresname='t1'));

OUTPUT:-

j)Findtheclassthatt1donotteachesatpresentsession.
SQL>selectclassfromteachingswhereextract(yearfromfsession)<>'2007'andsid=(selectsid

fromstaffswheresname='t1');

OUTPUT:-

8
a)Findthecollegeswhohavemostnumberofstaffs.
SQL>selectcname,count(sid)fromstaffjoinsgroupbycnamehavingcount(sid)>=(select

cname,max(count(sid))fromstaffjoinsgroupbycname);

OUTPUT:-

b)Findthestaffsthatearnahighersalarywhoearngreaterthanaveragesalaryth
eircollege.
SQL> selectsname,salaryfromstaffs,staffjoinswherestaffs.sid=staffjoins.sidand

salary>=(selectmax(salary)fromstaffjoins)andsalary>=(selectavg(salary)from

staffjoinswherecname='c1');

OUTPUT:-

c)Findthecollegeswhoseaveragesalaryismorethanaveragesalaryofc2.
SQL>selectcname,avg(salary)fromstaffjoinsgroupbycnamehavingavg(salary)>(select

avg(salary)fromstaffjoinswherecname='c2');

OUTPUT:-

9
d)Findthecollegethathasthesmallestpayroll.
SQL>selectcnamefromstaffjoinsgroupbycnamehavingsum(salary)=(selectmin(sum(salary))

fromstaffjoinsgroupbycname);

OUTPUT:-

e)Findthecollegeswherethetotalsalaryisgreaterthantheaveragesalaryofcolleges.

SQL>selectcname,sum(salary)fromstaffjoinsgroupbycnamehavingsum(salary)>(selectmax(a
vg(salary))fromstaffjoinsgroupbycname);

OUTPUT:-

k)Listthemaximum,minimum,averagesalaryofeachcollege.

SQL>selectcname,max(salary)"maxsalary",avg(salary)"avgsalary",min(salary)"minsalary"fromst
affjoinsgroupbycname;

OUTPUT:-

a) Listthenamesoftheteachers,departmentsteachinginmorethanonedepar
tment.

10
SQL>selectsname,deptfromstaffs,staffjoinswherestaffs.sid=staffjoins.sidandstaffs.sid

=(selectsidfromstaffjoinsgroupbysidhavingcount(dept)>1);

OUTPUT:-

b)Acquiredetailsofstaffsbynameinacollegeoreachcollege.

SQL>selectstaffs.sid,sname,saddress,contacts,cname,dept,doj,post,salaryfromsta
ffs,staffjoinswherestaffs.sid=staffjoins.sidorderbysname;

OUTPUT:-

c)FindthenamesofstaffthatearnmorethaneachstaffofC2College.

SQL>selectsnamefromstaffs,staffjoinswherestaffs.sid=staffjoins.sidandstaffs.sidin(selectsidfro

mstaffjoinswheresalary>=(selectmax(salary)fromstaffjoinswherecnamelike'c2'))andsta

ffjoins.cnamenotlike'c2';

11
OUTPUT:-

m) Listnamesofemployeesinascendingorderaccordingtosalarywhoareworkinginyour

collegeorallcolleges.

SQL>selectst.sid,st.sname,sj.salaryfromstaffsst,staffjoinssjwherest.sid=sj.sidorderby

sj.salary;

OUTPUT:-

a)Createaviewhavingfieldssname,cname,dept,DOJ,andpost.

SQL>createviewstaffdetailsasselectsname,cname,dept,doj,postfromstaffs,staffjoinswherestaffs
.sid=staffjoins.sid;

SQL>select*fromstaffdetails;

OUTPUT:-

12
b)Createaviewconsistingofcname,averagesalaryandtotalsalaryofallstaffinthatcol
lege.
SQL>createviewcollege_salasselectcname,round(avg(salary),2)"average",sum(salary)"total"

fromstaffjoinsgroupbycname;

SQL>select*fromcollege_sal;

OUTPUT:-

c).Listthestaffnamesofadepartmentusingaboveviews.
SQL>selectdept,cname,snamefromstaffdetailsswheres.dept=dept;

OUTPUT:-

13
14
PRACTICALNo:-2
QUES2:-Createthefollowingdatabase
Enrollment(enrollno,name,gender,DOB,address,phone)
Admission(admno,enrollno,course,yearsem,date,cname)
Colleges(cname,city,address,phone,afdate)
FeeStructure(course,yearsem,fee)
Payment(billno,admno,amount,pdate,purpose)

WriteSQLstatementsforthefollowing:-
a. Createtheabovetableswiththegivenspecificationsandconstraints.
b. Insertabout10rowsasareappropriatetosolvethefollowingqueries.
c. Getfulldetailofallstudentswhotookadmissionthisyearclasswise.
d. GetdetailofstudentswhotookadmissioninBhilaicolleges.
e. Calculatethetotalamountoffeescollectedinthissession

(i)Byyourcollege(ii)byeachcollege (iii)byallcolleges

a. Listthestudentswhohavenotpayedfullfees

(i) Inyourcollege(ii)inallcolleges

b. Listthenumberofadmissionsinyourclassineveryyear.

c. Listthestudentsinthesessionwhoarenotinthecollegesinthesamecityastheylivein.

d. Listthestudentsincollegesinyourcityandalsoliveinyourcity.

a. Createthetableswiththegivenspecificationsandconstraints.
QUE:CreatetableEnrollment(enrollno,name,gender,DOB,address,phone)
SQL>createtableenrollment(enrollnovarchar2(10)primarykey,namevarchar(10),gendervarchar2(7
),dobdate,addressvarchar2(20),phonenumber(10));
SQL>descenrollment;

15
QUE:CreatetableFeesstructure(course,yearsem,fee).

SQL>createtablefeestructure(coursevarchar2(10),yearsemvarchar2(10),feenumber(6),constraintfee
structureprimarykey(course,yearsem));

QUE:Createtablecollege(cname,city,address,phone,afdate).
SQL>createtablecollege(cnamevarchar2(10),cityvarchar2(10),addressvarchar2(10),phone

number(10),afdatedate,constraintcollegeprimarykey(cname));

QUE:Createtableadmission(admno,enrollno,course,yearsem,date,cname).

SQL>createtableadmission(admnonumber(10)primarykey,enrollnoreferencesenrollment,courseva
rchar(10),yearsemvarchar2(10),doadate,cnamereferencescollege,foreignkey(course,yearsem)ref
erencesfeestructure);

SQL>descadmission;

QUE:Createtablepayment(billno,admno,amount,pdate,purpose)

SQL>createtablepayment(billnovarchar2(5)primarykey,admnoreferencesadmission,amountnumb
er(8),pdatedate,purposevarchar2(15));

SQL>descpayment;

16
b.Insertabout10rowsasareappropriatetosolvethefollowingqueries.

1.INSERTROWSINENROLLMENT

SQL>insertintoenrollmentvalues('1001','sheetal','female','1-dec-
89','bhilai',9755078411);SQL>insertintoenrollmentvalues('1002','garima','female','20-april-
89','durg',9300178411);SQL>insertintoenrollmentvalues('1003','shilpa','female','24-feb-
90','bhilai',9300278411);SQL>insertintoenrollmentvalues('1004','sumi','female','18-dec-
88','housigbord',9300378411);SQL>insertintoenrollmentvalues('1005','avani','female','18-feb-
88','raipur',9847578411);SQL>insertintoenrollmentvalues('1006','bala','male','6-may-
88','bhilai',9875785684);
SQL>insertintoenrollmentvalues('1007','pratik','male','31-dec-
88','borsi',9875789684);SQL>insertintoenrollmentvalues('1008','jeet','male','9-sep-
89','bhilai',9893593562);SQL>insertintoenrollmentvalues('1009','sandeep','male','30-jan-
88','charoda',9755789684);SQL>insertintoenrollmentvalues('1010','swati','female','20-april-
88','durg',9755068799);SQL>select*fromenrollment;

INSERTROWSINFEESTRUCTURE
SQL>insertintofeestructurevalues('bca2','2009-2010',20000);
SQL>insertintofeestructurevalues('bca3','2009-2010',21000);
SQL>insertintofeestructurevalues('bca1','2009-2010',20000);
SQL>insertintofeestructurevalues('bcom3','2009-2010',22000);
SQL>insertintofeestructurevalues('bcom2','2007-2008',18000);
SQL>insertintofeestructurevalues('bcom1','2006-2007',10000);
SQL>insertintofeestructurevalues('bsc3','2009-2010',12000);

SQL>insertintofeestructurevalues('bba3','2004-2005',8000);
SQL>insertintofeestructurevalues('ba3','2004-2005',8000);
SQL>insertintofeestructurevalues('bca3','2007-2008',22000);
SQL>select*fromfeestructure;

17
INSERTROWSINCOLLEGE
SQL>insertintocollegevalues('shankara','bhilai','sec-6','2224567','19-jul-1990');

SQL>insertintocollegevalues('kalyan','durg','sec-7','2673656','1-feb-1990');

SQL>insertintocollegevalues('shivam','bhilai','hudco','2666756','19-july-1989');

SQL>insertintocollegevalues('bns','bhilai','sec-8','4553656','19-july-1998');

SQL>insertintocollegevalues('boysclg','durg','sec-1','4363656','21-feb-1998');

SQL>insertintocollegevalues('girlsclg','durg','sec-10','4563656','12-feb-1998');

SQL>insertintocollegevalues('Bit','camp','sec-10','2343656','12-march-1998');

SQL>insertintocollegevalues('science','raipur','sec-10','3373656','12-march-1998');

SQL>insertintocollegevalues('rungta','kohka','sec-2','4373656','12-april-1998');

SQL>insertintocollegevalues('dental','kohka','sec-2','4473656','1-aug-1988');

SQL>select*fromcollege;

INSERTROWSINADMISSION
SQL>insertintoadmissionvalues(1,'1001','bca2','2009-2010','1june2009','shankara');

SQL>insertintoadmissionvalues(2,'1002','bca2','2009-2010','1june2009','shankara');

SQL>insertintoadmissionvalues(3,'1003','bca1','2009-2010','15june-2009','kalyan');

18
SQL>insertintoadmissionvalues(4,'1004','bca3','2009-2010','1june2009','bns');

SQL>insertintoadmissionvalues(5,'1005','bcom1','2006-2007','1june2006','shankara');

SQL>insertintoadmissionvalues(6,'1006','bca2','2009-2010','1june2009','shankara');

SQL>insertintoadmissionvalues(7,'1007','bcom2','2007-2008','10june2009','Bit');

SQL>insertintoadmissionvalues(8,'1009','bcom2','2007-2008','11june2007','Bit');

SQL>insertintoadmissionvalues(9,'1009','bca2','2009-2010','1june2009','shankara');

SQL>insertintoadmissionvalues(10,'1010','bca2','2009-2010','15june2009','bns');

SQL>select*fromadmission;

INSERTROWSINPAYMENT
SQL>insertintopaymentvalues('b01',1,20000,'1june09','admission');

SQL>insertintopaymentvalues('b02',2,10000,'1june09','admission');

SQL>insertintopaymentvalues('b03',3,10000,'1june09','admission');

SQL>insertintopaymentvalues('b04',4,21000,'1june09','admission');

SQL>insertintopaymentvalues('b05',5,10000,'1june06','admission');

SQL>insertintopaymentvalues('b06',6,15000,'1june09','admission');

SQL>insertintopaymentvalues('b07',7,18000,'1june07','admission');

SQL>insertintopaymentvalues('b08',8,9000,'1june09','admission');

SQL>insertintopaymentvalues('b09',9,20000,'1june09','admission');

SQL>insertintopaymentvalues('b10',10,20000,'1june09','admission');

SQL>select*frompayment;

19
c. Getfulldetailofallstudentswhotookadmissionthisyearclasswise.
SQL>select*fromenrollmentwhereenrollnoin(selectenrollnofromadmissionwhere

to_char(date,yyyy)=’2009’);

OUTPUT:-

d.GetfulldetailofstudentswhotookadmissioninBhilaicollege.
SQL>select*fromenrollmentwhereenrollnoin(selectenrollnofromadmissionwherecnamein(selectcn
amefromcollegewherecity=’bhilai’));

OUTPUT:-

e. Calculatethetotalamountoffeescollectedinthissession

i) byyourcollege
20
SQL>selectsum(p.amount)“Totalfee”frompaymentp.admissionawherep.admno=a.admnoand
(a.yearsem=’2009-2010’)and(a.cname=‘bns’);
OUTPUT:-

ii)Byallcollege
SQL>selectsum(p.amount)“Totalfee”frompaymentp,admissionawherep.admno=a.admno

and(a.yearsem=’2009-2010’);
Output:-

e.a.Listthestudentwhohavenotpayfullfee.

i)Inyourcollege
SQL>selecte.namefromenrollmente,admissiona,feestructuref,paymentpwheree.enrollno=a.enrolln
oanda.course=f.courseanda.yearsem=f.yearsemanda.admno=p.admnoand
f.fee>p.amountanda.cname=’bns’;
OUTPUT:-

ii)Inallcollege
SQL>selecte.namefromenrollmente,admissiona,feestructuref,paymentpwheree.enrollno=a.enrollno
anda.course=f.courseanda.yearsem=f.yearsemanda.admno=p.admnoandf.fee>p.amount;

21
Output:-

e.c.Listthenamesofthestudentinthesessionwhoarenotinthecollegeinthesamecityastheyli
vein.
SQL>selecte.namefromenrollmente,admissiona,collegecwheree.enrollno=a.enrollnoanda.cname
=c.cnameande.address<>c.cityanda.yearsem=’2009-2010’;
Output:-

e.d.Listthenamesofthestudentinyourcollegeandcityandalsoliveinyourcity.

SQL>selecte.namefromenrollmente,admissiona,collegecwheree.enrollno=a.enrollnoanda.cnam
e=c.cnameande.address=c.city;
Output:-

22
PRACTICALNO.-03
OBJECT:-Usingthefollowingdatabase,
Subjects(paperid,subject,paper,papername)
Test(paperid,date,time,max,min)
Score(rollno,paperid,marks,attendance)
Students(admno,rollno,class,yearsem)

WriteSQLstatementsforthefollowing:-
a. Createtheabovetableswiththegivenspecificationsandconstraints.
b. Insertabout10rowsasareappropriatetosolvethefollowingqueries.
c. Listthestudentswhowerepresentinapaperofasubject.
d. Listallrollnumberswhohavepassedinfirstdivision.
e. ListallthestudentsinBCA-IIwhohavescoredhigherthanaverage
(i) inyourcollege(ii)ineverycollege
f. Listthehighestscore,averageandminimumscoreinBCA-II
(i) inyourcollege(ii)ineverycollege

a. Createthetableswiththegivenspecificationsandconstraints.

1)CreatetableSUBJECT
SQL>createtablesubject(paperidvarchar2(10)primarykey,subjectsvarchar2(20),paper

varchar2(10),papernamevarchar2(15));

SQL>descsubject;

2)CreatetableTEST
SQL>createtabletest(paperidreferencessubject,doedate,timevarchar2(10),max

varchar2(5),minvarchar2(5));

23
SQL>desctest;

3)CreatetableSCORE

SQL>createtablescore(rollnovarchar2(10)primarykey,paperidreferencessubject,marksnumb

er(5),attendencechar(1)check(attendence='a'orattendence='p'orattendence='A'oratten

dence='P'));

SQL>descscore;

4)CreatetableSTUDENTS

SQL>createtablestudents(admnovarchar2(5)primarykey,rollnoreferencesscore,classvarch
ar2(10),yearsemvarchar2(10));

SQL>descstudents;

OUTPUT:-

b)Insertabout10rowsasareappropriatetosolvethefollowingqueries.INSERT
ROWSINTOSUBJECT
SQL>insertintosubjectvalues('bca201a','maths','1','NA');

24
SQL>insertintosubjectvalues('bca201b','maths','2','calculus');

SQL>insertintosubjectvalues('bca201c','maths','3','datastructure');

SQL>insertintosubjectvalues('bca202','dbms','4','oracle');

SQL>insertintosubjectvalues('bca203','c++','5','vc++');

SQL>insertintosubjectvalues('bca204','networling','6','internetprgm');

SQL>insertintosubjectvalues('bca205','linux','7','vieditor');

SQL>insertintosubjectvalues('bca206a','english','8','management');

SQL>insertintosubjectvalues('bca206b','english','9','communication');

SQL>insertintosubjectvalues('bca209','optional','10','environment');

SQL>select*fromsubject;

OUTPUT:-

INSERTROWSINTOTEST
SQL>insertintotestvalues('bca201a','19-jan-2009','9:00am','50','25');

SQL>insertintotestvalues('bca201b','20-jan-2009','9:00am','50','25');

SQL>insertintotestvalues('bca201c','21-jan-2009','9:00am','50','25');

SQL>insertintotestvalues('bca202','22-jan-2009','9:00am','100','40');

SQL>insertintotestvalues('bca203','23-jan-2009','9:00am','100','40');

SQL>insertintotestvalues('bca204','27-jan-2009','9:00am','100','40');

SQL>insertintotestvalues('bca205','26-jan-2009','9:00am','50','25');

SQL>insertintotestvalues('bca206a','28-jan-2009','9:00am','50','25');

SQL>insertintotestvalues('bca206b','29-jan-2009','9:00am','50','25');

25
SQL>insertintotestvalues('bca209','02-feb-2009','9:00am','50','25');

SQL>select*fromtest;

OUTPUT:-

INSERTROWSINTOSCORE
SQL>insertintoscorevalues('101','bca201a',45,'p');

SQL>insertintoscorevalues('102','bca201b',40,'p');

SQL>insertintoscorevalues('103','bca201c',42,'p');

SQL>insertintoscorevalues('104','bca202',0,'p');

SQL>insertintoscorevalues('105','bca202',0,'a');

SQL>insertintoscorevalues('106','bca203',80,'p');

SQL>insertintoscorevalues('107','bca203',80,'p');

SQL>insertintoscorevalues('108','bca205',40,'p');

SQL>insertintoscorevalues('109','bca201a',40,'p');

SQL>insertintoscorevalues('110','bca204',72,'p');

SQL>select*fromscore;

26
OUTPUT:-

INSERTROWSINTOSTUDENTS
SQL>insertintostudentsvalues('01','101','bca2','2009-2010');

SQL>insertintostudentsvalues('2','101','bca2','2009-2010');

SQL>insertintostudentsvalues('3','103','bca2','2009-2010');

SQL>insertintostudentsvalues('4','104','bca2','2009-2010');

SQL>insertintostudentsvalues('5','105','bca2','2009-2010');

SQL>insertintostudentsvalues('6','106','bca2','2009-2010');

SQL>insertintostudentsvalues('7','107','bca2','2009-2010');

SQL>insertintostudentsvalues('8','108','bca2','2009-2010');

SQL>insertintostudentsvalues('9','109','bca2','2009-2010');

SQL>insertintostudentsvalues('10','110','bca2','2009-2010');

SQL>select*fromstudents;

OUTPUT:-

27
b.Listthestudentswhowerepresentinapaperofasubject.
SQL>selectstudents.rollnofromstudents,scorewhere(score.rollno=students.rollnoand

attendence='p');

Output:-

c.Listalltherollnumberswhohavepassedinfirstdivision.
SQL>selectrollnofromscorewheremarks>=60;

Output:-

d. ListallthestudentsinBCAIIwhohavescoredhigherthentheaverageinyourcollege.
SQL>selectstudents.rollno,marksfromstudents,scorewherestudents.rollno=score.rollnoand

marks>(selectavg(marks)fromscore,studentswhereclass='bca2'andscore.rollno=

students.rollno);

28
OUTPUT:-

e.Listthehighestscore,averageandminimumscoreinBCAIIinyourcollege.
SQL>selectmax(marks),avg(marks),min(marks)fromscore,studentswherescore.rollno=

students.rollnoandclass='bca2'groupbyclass;

Output:-

29
PRACTICALNO-04
QUES3:-Usingthefollowingdatabase,
Colleges(cname,city,address,phone,afdate)
Staffs(sid,sname,saddress,contacts)
StaffJoins(sid,cname,dept,DOJ,post,salary)
Teachings(sid,class,papered,fsession,tsession)
Subjects(paperid,subject,paperno,papername)

WriteSQLstatementsforthefollowing:-
a. Createtheabovetableswiththegivenspecificationsandconstraints.
b. Insertabout10rowsasareappropriatetosolvethefollowingqueries.
c. Listthenamesoftheteachersteachingcomputersubjects.
d. Listthenamesandcitiesofallstaffworkinginyourcollege.
e. Listthenamesandcitiesofallstaffworkinginyourcollegewhoearnmorethan15,000.

f) Createthetableswiththegivenspecificationsandconstraints.

QUE:CreateTableColleges(cname,city,address,phone,afdate)

SQL>createtablecolleges(cnamevarchar2(10)primarykey,cityvarchar2(15),addressvarchar2(1
5)notnull,phonenumber(10),afdatedate);

SQL>desccolleges;

QUE:CreateTablestaffs(sid,sname,saddress,contacts)
SQL>createtablestaffs(sidvarchar2(5)primarykey,snamevarchar2(15),saddress

varchar2(15),contactsnumber(10));

SQL>descstaffs;

30
QUE:CreateTableSubjects(paperid,subjects,paperno,papername)

SQL>createtablesubjects(paperidvarchar2(5)primarykey,subjectsvarchar2(15)notnull,papern
ovarchar2(5),papernamevarchar2(15)unique);

SQL> descsubjects;

QUE:CreateTableTeachings(sid,class,papered,fsession,tsession)

SQL>createtableteachings(sidvarchar2(5)referencesstaffs(sid),classvarchar2(10),paperidvarc
har2(5)referencessubjects(paperid),fsessiondate,tsessiondate);

SQL> descteachings;

QUE:Createtablestaffjoins(sid,cname,dept,doj,post,salary)

SQL>createtablestaffjoins(sidvarchar2(5)referencesstaffs(sid),cnamevarchar2(10)references
colleges(cname),deptvarchar2(10),dojdatenotnull,postvarchar2(10),salarynumber(5))

SQL> descstaffjoins;

31
g)Insertabout10rowsasareappropriatetosolvethefollowingqueries.

INSERTROWSINTOCOLLEGES
SQL>insertintocollegesvalues('c1','bhilai','sec-6',07882225487,'12jan1985');

SQL>insertintocollegesvalues('c2','raipur','ashoknagar',07712225487,'1jan1980');

SQL>insertintocollegesvalues('c3','rajnandgav','dipaknagar',07722225487,'3mar1981');

SQL>insertintocollegesvalues('c4','rajnandgav','ashishnagar',07722225457,'2april1991');

SQL>insertintocollegesvalues('c5','durg','padmnabpur',07702225357,'15jan1996');

SQL>insertintocollegesvalues('c6','durg','kelabadi',07702278357,'15jan1984');

SQL>insertintocollegesvalues('c7','bhilai','sec-10',07882278357,'15feb1988');

SQL>insertintocollegesvalues('c8','bhilai','hudco',07882278456,'1july1980');

SQL>insertintocollegesvalues('c9','bhilai','sec-11',07882278456,'1mar1979');

SQL>insertintocollegesvalues('c10','bhilai','nehrunagar',07882278456,'10aug1980');

SQL>select*fromcolleges;

OUTPUT:-

INSERTROWSINTOSTAFFS
SQL>insertintostaffsvalues('c101','ramakrishna','bhilai’,9857842154);

SQL>insertintostaffsvalues('c102','rama','bhilai’,9300975784);

SQL>insertintostaffsvalues('c103','manyata','raipur’,9300975684);

SQL>insertintostaffsvalues('c201','t1','durg',9755275684);

32
SQL>insertintostaffsvalues('c202','t2','durg',9755458744);

SQL>insertintostaffsvalues('c301','n1','bhilai',9755458747);

SQL>insertintostaffsvalues('c401','n2','raipur',9855458747);

SQL>insertintostaffsvalues('c501','t3','raipur',9857442154);

SQL>insertintostaffsvalues('c601','t5','bhilai',9827845987);

SQL>insertintostaffsvalues('c701','t5','durg',9727845987);

SQL>select*fromstaffs;

OUTPUT:-

INSERTROWSINTOSTAFFJOINS
SQL>insertintostaffjoinsvalues('c101','c3','computer','1mar2009','teacher',10000);

SQL>insertintostaffjoinsvalues('c102','c1','maths','1april2009','principal',17000);

SQL>insertintostaffjoinsvalues('c103','c2','maths','1april2007','teacher',17000);

SQL>insertintostaffjoinsvalues('c301','c2',’science','1april2005','clerk',1000);

SQL>insertintostaffjoinsvalues('c401','c5','arts','9may2004','clerk',1000);

SQL>insertintostaffjoinsvalues('c501','c6','eng','1march2002','vprincipal',12000);

SQL>insertintostaffjoinsvalues('c601','c7','hindi','12april2007','teacher',10000);

SQL>insertintostaffjoinsvalues('c701','c8','commerce','1mar2009','teacher',10000);

SQL>insertintostaffjoinsvalues('c601','c9','maths','1aug2009','hod',11000);

SQL>insertintostaffjoinsvalues('c501','c10','hindi','1july2009','hod',11000);

SQL>select*fromstaffjoins;

33
OUTPUT:-

INSERTROWSINTOSUBJECTS
SQL>insertintosubjectsvalues('p1','computer','101','dbms');

SQL>insertintosubjectsvalues('p2','arts','102','dance');

SQL>insertintosubjectsvalues('p3','finearts','103','sketching');

SQL>insertintosubjectsvalues('p4','maths','104','calculus');

SQL>insertintosubjectsvalues('p5','enghish','105','foundation');

SQL>insertintosubjectsvalues('p6','economics','106','statsistics');

SQL>insertintosubjectsvalues('p7','bussinesstds','107','accounts');

SQL>insertintosubjectsvalues('p8','hindi','109','mainreader');

SQL>insertintosubjectsvalues('p9','socialstudies','109','history');

SQL>insertintosubjectsvalues('p10','science','110','physics');

SQL>select*fromsubjects;

OUTPUT:-

34
INSERTROWSINTOTEACHINGS:
SQL>insertintoteachingsvalues('c101','bca2','p1','1jan2007','1jan2009');

SQL>insertintoteachingsvalues('c102','bca2','p4','1mar2005','31mar2009');

SQL>insertintoteachingsvalues('c201','bca1','p5','1jan2006','1jan2009');

SQL>insertintoteachingsvalues('c301','bcom2','p6','1aug2007','1aug2009');

SQL>insertintoteachingsvalues('c401','bcom1','p7','1july2002','1july2009');

SQL>insertintoteachingsvalues('c501','bcom2','p5','1sep2003','1sep2009');

SQL>insertintoteachingsvalues('c601','bsc1','p10','1feb2001','31mar2009');

SQL>insertintoteachingsvalues('c701','bsc2',’p10','1mar2007','31mar2009');

SQL>insertintoteachingsvalues('c103','bba2','p7','1july2004','1july2009');

SQL>insertintoteachingsvalues('c202',’bba1','p2','1jan2003','1jan2009');

SQL>select*fromteachings;

OUTPUT:-

a.Listthenamesoftheteachersteachingcomputersubject.

SQL>selectsnamefromstaffswheresid=(selectsidfromteachingswherepaperid=(selectpaperidfrom
subjectswheresubjects='computer'));

Output:-

35
b.Listallthenamesandcitiesofallstaffworkinginyourcollege.
SQL>selectsname,saddressfromstaffswheresid=(selectsidfromstaffjoinswhere

cname='c1');

Output:-

c.Listthenameofthecitiesofallstaffsworkinginyourcollegeswhoearnmorethan15000.

SQL>selectsname,saddressfromstaffswheresid=(selectsidfromstaffjoinswherecname='c1'ands
alary>15000);

Output:-

36
PRACTICALNO-05
OBJECT:-Usingthefollowingdatabase
Colleges(cname,city,address,phone,afdate)
Staffs(sid,sname,saddress,contacts)
StaffJoins(sid,cname,dept,DOJ,post,salary)
Teachings(sid,class,papered,fsession,tsession)
Subjects(paperid,subject,paperno,papername)
a. Findthestaffswhosenamesstartwith‘M’or‘R’andendswith‘A’and/or7characterslong.
b. Findthestaffswhosedateofjoiningis2005.
c. ModifythedatabasesothatstaffN1nowworksinC2College.
d. Listthenamesofsubjects,whichT1teachesinthissessionorallsessions.
a. Findthestaffswhosenamesstartswith‘m’or‘r’endswith‘a’and/or7characterslong.
SQL>selectsnamefromstaffswheresnamelike'm_____a%'orsnamelike'r%a';

Output:-

b.Findthestaffswhosedateofjoiningis2005.

SQL>selectsnamefromstaffswheresid=(selectsidfromstaffjoinswhereextract(yearfromdoj)=’2005’
);

Output:-

c.Modifythedatabasesothatstaffsn1nowworksinc2college.
SQL>updatestaffjoinssetcname='c2'wheresid=(selectsidfromstaffswheresname='n1');

SQL>select*fromstaffjoins;

Output:-
37
d.Listthenameofsubjectwhicht1teachesinthissessionorallsession.
SQL>selectsubjectsfromsubjectswherepaperid=(selectpaperidfromteachingswhere

(extract(yearfromfsession)=’2009’orfsessionisnotnull)andsid=(selectsidfromstaffs

wheresname='t1'));

Output:-

38
PRACTICALNO-06
QUES6:-Usingthefollowingdatabase
Colleges(cname,city,address,phone,afdate)
Staffs(sid,sname,saddress,contacts)
StaffJoins(sid,cname,dept,DOJ,post,salary)
Teachings(sid,class,papered,fsession,tsession)
Subjects(paperid,subject,paperno,papername)

WriteSQLstatementsforthefollowing:-
a. FindtheclassesthatT1donotteachatpresentsession.
b. Findthecollegeswhohavemostnumberofstaffs.
c. Findthestaffsthatearnahighersalarywhoearngreaterthanaveragesalaryoftheircollege.
d. FindthecollegeswhoseaveragesalaryismorethanaveragesalaryofC2.
e. Findthecollegethathasthesmallestpayroll.
f. Findthecollegewherethetotalsalaryisgreaterthantheaveragesalaryofallcolleges.
g. Listthemaximum,average,minimumsalaryofeachcollege.
a. Findtheclassthatt1donotteachesatpresentsession.

SQL>selectclassfromteachingswhereextract(yearfromfsession)<>’2007’andsid=(selectsidfromsta
ffswheresname='t1');

Output:-

b.Findthecollegeswhohavemostnumberofstaffs.

SQL>selectcname,count(sid)fromstaffjoinsgroupbycnamehavingcount(sid)>=(selectcname,max(
count(sid))fromstaffjoinsgroupbycname)

Output:-

39
c. Findthestaffsthatearnahighersalarywhoearngreaterthanaveragesalaryoftheircolle
ge.

SQL>selectsname,salaryfromstaffs,staffjoinswherestaffs.sid=staffjoins.sidandsalary>=(selectma
x(salary)fromstaffjoins)andsalary>=(selectavg(salary)fromstaffjoinswherecname='c1');

Output:-

d. Findthecollegeswhoseaveragesalaryismorethanaveragesalaryofc2.
SQL>selectcname,avg(salary)fromstaffjoinsgroupbycnamehavingavg(salary)>(select

avg(salary)fromstaffjoinswherecname='c2');

Output:-

e.Findthecollegethathasthesmallestpayroll.
SQL>selectcnamefromstaffjoinsgroupbycnamehavingsum(salary)=(selectmin(sum(salary))

fromstaffjoinsgroupbycname);

Output:-

f. Findthecollegeswherethetotalsalaryisgreaterthantheaveragesalaryof

40
allcolleges.
SQL>selectcname,sum(salary)fromstaffjoinsgroupbycnamehavingsum(salary)>(select

max(avg(salary))fromstaffjoinsgroupbycname);

Output:-

g.Listthemaximum,minimum,averagesalaryofeachcollege.
SQL>selectcname,max(salary)"maxsalary",avg(salary)"avgsalary",min(salary)"minsalary"

fromstaffjoinsgroupbycname;

Output:-

41
PRACTICALNO-07
QUES7:-Usingthefollowingdatabase,
Colleges(cname,city,address,phone,afdate)

Staffs(sid,sname,saddress,contacts)
StaffJoins(sid,cname,dept,DOJ,post,salary)
Teachings(sid,class,papered,fsession,tsession)
Subjects(paperid,subject,paperno,papername)

WriteSQLstatementsforthefollowing:-
a. FindtheclassesthatT1donotteachatpresentsession.
b. Listthenamesoftheteachers,departmentsteachinginmorethanonedepartment.
c. Acquiredetailsofstaffsbynameinacollegeoreachcollege.
d. FindthenamesofstaffthatearnmorethaneachstaffofC2college.
e. Giveallprincipala10%riseinsalaryunlesstheirsalarybecomesgreaterthan20,000insuchcasesgive
5%rise.
f. Findallstaffthatdonotworkinsamecitiesasthecollegestheywork.
g. Listnamesofemployeesinascendingorderaccordingtosalarywhoareworkinginyourcollegeorallc
olleges.
a. Findtheclassthatt1donotteachesatpresentsession.

SQL>selectclassfromteachingswhereextract(yearfromfsession)<>’2007’andsid=(selectsidfromstaf
fswheresname='t1');

Output:-

b.Listthenameoftheteachersdepartmentteachinginmorethan1department.

SQL>selectsname,deptfromstaffs,staffjoinswherestaffs.sid=staffjoins.sidandstaffs.sid=(selectsidfrom
staffjoinsgroupbysidhavingcount(dept)>1);

Output:-

42
c.Acquiredetailsofstaffsbynameinacollegesoreachcollege.

SQL>selectstaffs.sid,sname,saddress,contacts,cname,dept,doj,post,salaryfromstaffs,staffjoinswherest
affs.sid=staffjoins.sidorderbysname;

Output:-

d.FindthenamesofthestaffthatearnmorethaneachstaffofC2college.

SQL>selectsnamefromstaffs,staffjoinswherestaffs.sid=staffjoins.sidandstaffs.sidin(selectsidfromsta

ffjoinswheresalary>=(selectmax(salary)fromstaffjoinswherecnamelike'c2'))andstaffjoins.cna

menotlike'c2';

Output:-

e.Findthestaffthatdoesnotworkinsamecitiesasthecollegetheywork.

SQL>selectsnamefromcolleges,staffswherecolleges.city!=staffs.saddressandcolleges.cname=staffs.c
name;

Output:-

43
f. Listthenamesoftheemployeesinascendingorderaccordingtosalarybecomesgreaterwh
oworkinyourcollegeorallcollege.
SQL>Selectst.sid,st.sname,sj.salaryfromstaffsst,staffjoinssjwherest.sid=sj.sidorderbysj.salary;

Output:-

44
PRACTICALNO-08
QUES8:-Usingthefollowingdatabase,
Colleges(cname,city,address,phone,afdate)
Staffs(sid,sname,saddress,contacts)
StaffJoins(sid,cname,dept,DOJ,post,salary)
Teachings(sid,class,papered,fsession,tsession)
Subjects(paperid,subject,paperno,papername)

WriteSQLstatementsforthefollowing:-
a. FindtheclassesthatT1donotteachatpresentsession.
b. Createaviewhavingfieldssname,cname,dept,DOJ,andpost.
c. Createaviewconsistingofcname,averagesalaryandtotalsalaryofallstaffinthatcollege.
d. Selectthecollegeshavinghighestandlowestaveragesalaryusingaboveviews.
e. Listthestaffnamesofadepartmentusingaboveviews.

a.Findtheclassthatt1donotteachesatpresentsession.
SQL>selectclassfromteachingswhereextract(yearfromfsession)<>’2007’andsid=(selectsid

fromstaffswheresname='t1');

Output:-

b.Createaviewhavingfieldssname,dept,dojandpost.
SQL>createviewstaffdetailsasselectsname,cname,dept,doj,postfromstaffs,staffjoinswhere

staffs.sid=staffjoins.sid;

SQL>select*fromstaffdetails;

45
Output:-

c. Createaviewconsistingofcnameaveragesalaryandtotalsalaryofallstaffinthatcolleges.
SQL>createviewcollege_salasselectcname,round(avg(salary),2)"Average",sum(salary)"Total"

fromstaffjoinsgroupbycname;

SQL>select*fromcollege_sal;

OUTPUT:-

d.Listthestaffnamesofadepartmentusingaboveviews.
SQL>selectdept,cname,snamefromstaffdetailsswheres.dept=dept;

Output:-

46
PRACTICALNO-09
QUES9:-Createthefollowingdatabase
Enrollment(enrollno,name,gender,DOB,address,phone)

Admission(admno,enrollno,course,yearsem,date,cname)
Colleges(cname,city,address,phone,afdate)
FeeStructure(course,yearsem,fee)
Payment(billno,admno,amount,pdate,purpose)

WriteSQLstatementsforthefollowing:-
a. Createtheabovetableswiththegivenspecificationsandconstraints.
b. Insertabout10rowsasareappropriatetosolvethefollowingqueries.
c. Getfulldetailofallstudentswhotookadmissionthisyearclasswise.
d. GetdetailofstudentswhotookadmissioninBhilaicolleges.
e. Calculatethetotalamountoffeescollectedinthissession

(i)Byyourcollege(ii)byeachcollege (iii)byallcollege

a.Createthetableswiththegivenspecificationsandconstraints.

QUE:CreatetableEnrollment(enrollno,name,gender,DOB,address,phone)

SQL>createtableenrollment(enrollnovarchar2(10)primarykey,namevarchar(10),gendervarch
ar2(7),dobdate,addressvarchar2(20),phonenumber(10));

SQL>descenrollment;

QUE:CreatetableFeesstructure(course,yearsem,fee).

SQL>createtablefeestructure(coursevarchar2(10),yearsemvarchar2(10),feenumber(6),constr
aintfeestructureprimarykey(course,yearsem));

47
QUE:Createtablecollege(cname,city,address,phone,afdate).

SQL>createtablecollege(cnamevarchar2(10),cityvarchar2(10),addressvarchar2(10),phonenu
mber(10),afdatedate,constraintcollegeprimarykey(cname));

QUE:Createtableadmission(admno,enrollno,course,yearsem,date,cname)

SQL>createtableadmission(admnonumber(10)primarykey,enrollnoreferencesenrollment,cou
rsevarchar(10),yearsemvarchar2(10),doadate,cnamereferencescollege,foreignkey(cour
se,yearsem)referencesfeestructure);

SQL>descadmission;

QUE:Createtablepayment(billno,admno,amount,pdate,purpose)

SQL>createtablepayment(billnovarchar2(5)primarykey,admnoreferencesadmission,amountn
umber(8),pdatedate,purposevarchar2(15));

SQL>descpayment;

b.Insertabout10rowsasareappropriatetosolvethefollowingqueries.

INSERTROWSINENROLLMENT
SQL>insertintoenrollmentvalues('1001','sheetal','female','1-dec-89','bhilai',9755078411);

SQL>insertintoenrollmentvalues('1002','garima','female','20-april-89','durg',9300178411);

SQL>insertintoenrollmentvalues('1003','shilpa','female','24-feb-90','bhilai',9300278411);
48
SQL>insertintoenrollmentvalues('1004','sumi','female','18-dec-88','housigbord',9300378411);

SQL>insertintoenrollmentvalues('1005','avani','female','18-feb-88','raipur',9847578411);

SQL>insertintoenrollmentvalues('1006','bala','male','6-may-88','bhilai',9875785684);

SQL>insertintoenrollmentvalues('1007','pratik','male','31-dec-88','borsi',9875789684);

SQL>insertintoenrollmentvalues('1009','sandeep','male','30-jan-88','charoda',9755789684);

SQL>insertintoenrollmentvalues('1009','jeet','male','9-sep-89','bhilai',9893593562);

SQL>insertintoenrollmentvalues('1010','swati','female','20-april-88','durg',9755068799);

SQL>select*fromenrollment;

OUTPUT:-

INSERTROWSINFEESTRUCTURE
SQL>insertintofeestructurevalues('bca2','2009-2010',20000);

SQL>insertintofeestructurevalues('bca3','2009-2010',21000);

SQL>insertintofeestructurevalues('bca1','2009-2010',20000);

SQL>insertintofeestructurevalues('bcom3','2009-2010',22000);

SQL>insertintofeestructurevalues('bcom2','2007-2008',18000);

SQL>insertintofeestructurevalues('bcom1','2006-2007',10000);

SQL>insertintofeestructurevalues('bsc3','2009-2010',12000);

SQL>insertintofeestructurevalues('bba3','2004-2005',8000);

SQL>insertintofeestructurevalues('ba3','2004-2005',8000);

SQL>insertintofeestructurevalues('bca3','2007-2008',22000);

SQL>select*fromfeestructure;

49
OUTPUT:-

INSERTROWSINCOLLEGE
SQL>insertintocollegevalues('shankara','bhilai','sec-6','2224567','19-jul-1990');

SQL>insertintocollegevalues('kalyan','durg','sec-7','2673656','1-feb-1990');

SQL>insertintocollegevalues('shivam','bhilai','hudco','2666756','19-july-1989');

SQL>insertintocollegevalues('bns','bhilai','sec-8','4553656','19-july-1998');

SQL>insertintocollegevalues('boysclg','durg','sec-1','4363656','21-feb-1998');

SQL>insertintocollegevalues('girlsclg','durg','sec-10','4563656','12-feb-1998');

SQL>insertintocollegevalues('Bit','camp','sec-10','2343656','12-march-1998');

SQL>insertintocollegevalues('science','raipur','sec-10','3373656','12-march-1998');

SQL>insertintocollegevalues('rungta','kohka','sec-2','4373656','12-april-1998');

SQL>insertintocollegevalues('dental','kohka','sec-2','4473656','1-aug-1988');

SQL>select*fromcollege;

OUTPUT:-

50
INSERTROWSINADMISSION
SQL>insertintoadmissionvalues(1,'1001','bca2','2009-2010','1june2009','shankara');

SQL>insertintoadmissionvalues(2,'1002','bca2','2009-2010','1june2009','shankara');

SQL>insertintoadmissionvalues(3,'1003','bca1','2009-2010','15june-2009','kalyan');

SQL>insertintoadmissionvalues(4,'1004','bca3','2009-2010','1june2009','bns');

SQL>insertintoadmissionvalues(5,'1005','bcom1','2006-2007','1june2006','shankara');

SQL>insertintoadmissionvalues(6,'1006','bca2','2009-2010','1june2009','shankara');

SQL>insertintoadmissionvalues(7,'1007','bcom2','2007-2008','10june2009','Bit');

SQL>insertintoadmissionvalues(8,'1009','bcom2','2007-2008','11june2007','Bit');

SQL>insertintoadmissionvalues(9,'1009','bca2','2009-2010','1june2009','shankara');

SQL>insertintoadmissionvalues(10,'1010','bca2','2009-2010','15june2009','bns');

SQL>select*fromadmission;

OUTPUT:-

INSERTROWSINPAYMENT
SQL>insertintopaymentvalues('b01',1,20000,'1june09','admission');

SQL>insertintopaymentvalues('b02',2,10000,'1june09','admission');

SQL>insertintopaymentvalues('b03',3,10000,'1june09','admission');

SQL>insertintopaymentvalues('b04',4,21000,'1june09','admission');

SQL>insertintopaymentvalues('b05',5,10000,'1june06','admission');

SQL>insertintopaymentvalues('b06',6,15000,'1june09','admission');

51
SQL>insertintopaymentvalues('b07',7,18000,'1june07','admission');

SQL>insertintopaymentvalues('b09',8,9000,'1june09','admission');

SQL>insertintopaymentvalues('b09',9,20000,'1june09','admission');

SQL>insertintopaymentvalues('b10',10,20000,'1june09','admission');

SQL>select*frompayment;

OUTPUT:-

c.Getfulldetailofallstudentswhotookadmissionthisyearclasswise.
SQL>select*fromenrollmentwhereenrollnoin(selectenrollnofromadmissionwhere

to_char(date,yyyy)=’2009’);

Output:-

a.GetfulldetailofstudentswhotookadmissioninBhilaicollege.
SQL>select*fromenrollmentwhereenrollnoin(selectenrollnofromadmissionwherecnamein
(selectcnamefromcollegewherecity=’bhilai’));
Output:-

52
e.Calculatethetotalamountoffeescollectedinthissession

i)Byyourcollege
SQL>selectsum(p.amount)“Totalfee”frompaymentp,admissionawherep.admno=a.admnoand(a.years
em=’2009-2010’)and(a.cname=‘bns’);
Output:-

ii)Byallcollege
SQL>selectsum(p.amount)“Totalfee”frompaymentp,admissionawherep.admno=a.admnoand(a.years
em=’2009-2010’);
Output:-

53
PRACTICALNO-10
QUES10:-Createthefollowingdatabase,
Enrollment(enrollno,name,gender,DOB,address,phone)
Admission(admno,enrollno,course,yearsem,date,cname)
Colleges(cname,city,address,phone,afdate)
FeeStructure(course,yearsem,fee)
Payment(billno,admno,amount,pdate,purpose)

WriteSQLstatementsforthefollowing:-
a. Listthestudentswhohavenotpayedfullfees

(i) Inyourcollege(ii)inallcolleges

b. Listthenumberofadmissionsinyourclassineveryyear.
c. Listthestudentsinthesessionwhoarenotinthecollegesinthesamecityastheylivein.
d. Listthestudentsincollegesinyourcityandalsoliveinyourcity.

a.Listthestudentwhohavenotpayfullfee.i)Inyo
urcollege
SQL>selecte.namefromenrollmente,admissiona,feestructuref,paymentpwheree.enrollno=a.enrollno
anda.course=f.courseanda.yearsem=f.yearsemanda.admno=p.admnoandf.fee>p.amountanda.
cname=’bns’;
Output:-

ii)Inallcollege
SQL>selecte.namefromenrollmente,admissiona,feestructuref,paymentpwheree.enrollno=a.enrolln
oanda.course=f.courseanda.yearsem=f.yearsemanda.admno=p.admnoandf.fee>p.amount;

54
Output:-

c.Listthenamesofthestudentinthesessionwhoarenotinthecollegeinthesamecity
astheylivein.
SQL>selecte.namefromenrollmente,admissiona,collegecwheree.enrollno=a.enrollnoanda.cname
=c.cnameande.address<>c.cityanda.yearsem=’2009-2010’;
Output:-

d.Listthenamesofthestudentinyourcollegeandcityandalsoliveinyourcity.
SQL>selecte.namefromenrollmente,admissiona,collegecwheree.enrollno=a.enrollnoanda.cnam
e=c.cnameande.address=c.city;
Output:-

55
PRACTICALNO.-11
QUES11:-Usingthefollowingdatabase,
Subjects(paperid,subject,paper,papername)

Test(paperid,date,time,max,min)
Score(rollno,paperid,marks,attendance)
Students(admno,rollno,class,yearsem)

WriteSQLstatementsforthefollowing:-
a. Createtheabovetableswiththegivenspecificationsandconstraints.
b. Insertabout10rowsasareappropriatetosolvethefollowingqueries.
c. Listthestudentswhowerepresentinapaperofasubject.
d. Listallrollnumberswhohavepassedinfirstdivision.
e. ListallthestudentsinBCA-IIwhohavescoredhigherthanaverage
(i) inyourcollege(ii)ineverycollege
f.Listthehighestscore,averageandminimumscoreinBCA-II
(i) inyourcollege(ii)ineverycollege

a. Createthetableswiththegivenspecificationsandconstraints.QUE:Cr
eatetableSUBJECT(paperid,subject,paper,papername)
SQL>createtablesubject(paperidvarchar2(10)primarykey,subjectsvarchar2(20),paper

varchar2(10),papernamevarchar2(15));

SQL>descsubject;

56
QUE:CreatetableTEST(paperid,date,time,max,min)

SQL>createtabletest(paperidreferencessubject,doedate,timevarchar2(10),maxvarcha
r2(5),minvarchar2(5));

SQL>desctest;

QUE:CreatetableSCORE(rollno,paperid,marks,attendance)

SQL>createtablescore(rollnovarchar2(10)primarykey,paperidreferencessubject,marksnumb

er(5),attendencechar(1)check(attendence='a'orattendence='p'orattendence='A'oratten

dence='P'));

SQL>descscore;

QUE:CreatetableSTUDENTS(admno,rollno,class,yearsem)

SQL>createtablestudents(admnovarchar2(5)primarykey,rollnoreferencesscore,classvarch
ar2(10),yearsemvarchar2(10));

SQL>descstudents;

57
b.Insertabout10rowsasareappropriatetosolvethefollowingqueries.

INSERTROWSINTOSUBJECT
SQL>insertintosubjectvalues('bca201a','maths','1','NA');

SQL>insertintosubjectvalues('bca201b','maths','2','calculus');

SQL>insertintosubjectvalues('bca201c','maths','3','datastructure');

SQL>insertintosubjectvalues('bca202','dbms','4','oracle');

SQL>insertintosubjectvalues('bca203','c++','5','vc++');

SQL>insertintosubjectvalues('bca204','networling','6','internetprgm');

SQL>insertintosubjectvalues('bca205','linux','7','vieditor');

SQL>insertintosubjectvalues('bca206a','english','8','management');

SQL>insertintosubjectvalues('bca206b','english','9','communication');

SQL>insertintosubjectvalues('bca209','optional','10','environment');

SQL>select*fromsubject;

OUTPUT:-

58
INSERTROWSINTOTEST
SQL>insertintotestvalues('bca201a','19-jan-2009','9:00am','50','25');

SQL>insertintotestvalues('bca201b','20-jan-2009','9:00am','50','25');

SQL>insertintotestvalues('bca201c','21-jan-2009','9:00am','50','25');

SQL>insertintotestvalues('bca202','22-jan-2009','9:00am','100','40');

SQL>insertintotestvalues('bca203','23-jan-2009','9:00am','100','40');

SQL>insertintotestvalues('bca204','27-jan-2009','9:00am','100','40');

SQL>insertintotestvalues('bca205','26-jan-2009','9:00am','50','25');

SQL>insertintotestvalues('bca206a','28-jan-2009','9:00am','50','25');

SQL>insertintotestvalues('bca206b','29-jan-2009','9:00am','50','25');

SQL>insertintotestvalues('bca209','02-feb-2009','9:00am','50','25');

SQL>select*fromtest;

OUTPUT:-

INSERTROWSINTOSCORE
SQL>insertintoscorevalues('101','bca201a',45,'p');

SQL>insertintoscorevalues('102','bca201b',40,'p');

SQL>insertintoscorevalues('103','bca201c',42,'p');

SQL>insertintoscorevalues('104','bca202',0,'p');

59
SQL>insertintoscorevalues('105','bca202',0,'a');

SQL>insertintoscorevalues('106','bca203',80,'p');

SQL>insertintoscorevalues('107','bca203',80,'p');

SQL>insertintoscorevalues('109','bca205',40,'p');

SQL>insertintoscorevalues('109','bca201a',40,'p');

SQL>insertintoscorevalues('110','bca204',72,'p');

SQL>select*fromscore;

OUTPUT:-

INSERTROWSINTOSTUDENTS
SQL>insertintostudentsvalues('01','101','bca2','2009-2010');

SQL>insertintostudentsvalues('2','101','bca2','2009-2010');

SQL>insertintostudentsvalues('3','103','bca2','2009-2010');

SQL>insertintostudentsvalues('4','104','bca2','2009-2010');

SQL>insertintostudentsvalues('5','105','bca2','2009-2010');

SQL>insertintostudentsvalues('6','106','bca2','2009-2010');

SQL>insertintostudentsvalues('7','107','bca2','2009-2010');

SQL>insertintostudentsvalues('8','109','bca2','2009-2010');

SQL>insertintostudentsvalues('9','109','bca2','2009-2010');

SQL>insertintostudentsvalues('10','110','bca2','2009-2010');

SQL>select*fromstudents;

60
OUTPUT:-

c.Listthestudentswhowerepresentinapaperofasubject.

SQL>selectstudents.rollnofromstudents,scorewhere(score.rollno=students.rollnoandattendenc
e='p');

Output:-

d.Listalltherollnumberswhohavepassedinfirstdivision.
SQL>selectrollnofromscorewheremarks>=60;

Output:-

61
e.ListallthestudentsinBCAIIwhohavescoredhigherthentheaverageinyourcoll
ege.
SQL>selectstudents.rollno,marksfromstudents,scorewherestudents.rollno=score.rollnoand

marks>(selectavg(marks)fromscore,studentswhereclass='bca2'andscore.rollno=

students.rollno);

Output:-

f.Listthehighestscore,averageandminimumscoreinBCAIIinyourcollege.

SQL>selectmax(marks),avg(marks),min(marks)fromscore,studentswherescore.rollno=students.
rollnoandclass='bca2'groupbyclass;

Output:-

62

You might also like