Upload
sivamuthucse
View
217
Download
0
Embed Size (px)
Citation preview
8/10/2019 Lab Manual 16
1/95
Department
Of
Computer Science & Engineering
Data Base Management Systems Lab Manual
ALAJI INSTITUTE OF TECHNOLOGY AND
SCIENCE
Department of computer science & engineering
In-charge HOD rincipal
repare! by" #ppro$e! &
%e$iee! by"
Issue! by" 'e'f Date"
8/10/2019 Lab Manual 16
2/95
Department of Computer Science and Engineering
ALAJI INSTITUTE OF TECHNOLOGY AND SCIENCE
Laknepally(V), Narsampet, Warangal
DE#%(ME)( O* COM+(E% SCIE)CE & E),I)EE%I),
Lab Manual for the Academic Year !""#"
($n accordance %ith &N' syllabus)
*&+' - .*M LA*
'/+AM - +
0121.
Balaji Institute of Technology and Science 2
8/10/2019 Lab Manual 16
3/95
Department of Computer Science and Engineering
I)DE
S' )o Contents age' no
" Lab 2b3ecti4e 5
$ntroduction About Lab 6
7tandard 2perating 8rocedure 928
:
7 ;uidelines to tudents =Lstatements and .?1
@
6List of Lab +ercises51" yllabus 8rograms (&N')51 Additional 8rograms
"!
B *ackground 'heory "6
: olutions for 8rograms "
< 8L#Cl 8rograms 6"
@ Additional Vi4a =uestion
8/10/2019 Lab Manual 16
4/95
Department of Computer Science and Engineering
L#B OB.EC(I/E
pon successful completion of this Lab the student %ill be able to-
reating database ob3ects
Modifying database ob3ects
Manipulating the data
/etrie4ing the data from the database ser4er
8erforming database operations in a procedural manner using pl>sCl
8erforming database operations (create, update, modify, retrie4e, etc1,)
using front#end tools like .?1
.esign and .e4elop applications like banking, reser4ation system, etc1,
Balaji Institute of Technology and Science 4
8/10/2019 Lab Manual 16
5/95
Department of Computer Science and Engineering
I)(%OD+C(IO) #BO+( L#B
'here are BB systems ( ompaC 8resario ) installed in this Lab1
'heir configurations are as follo%s-
8rocessor - AM. Athelon D "1B: ;0E
/AM - 6B M*
0ard .isk - 5! ;*
Mouse - 2ptical Mouse
Net%ork $nterface card - 8resent
Softare
All systems are configured in D+#L BOO(mode i1e1, tudents can boot
from Windo%s F8 or Linu as per their lab reCuirement1 'his is 4ery useful
for students because they are familiar %ith different 2perating ystems sothat they can eecute their programs in different programming
en4ironments1
+ach student has a separate login for database access
Oracle 0i client 4ersion is installed in all systems1 2n the ser4er,
account for each student has been created1
'his is 4ery useful because students can sa4e their %ork
(scenariosG, pl > sCl programs, data related pro3ects, etc) in their o%n
accounts1 +ach student %ork is safe and secure from other students1
Latest 'echnologies like DO( )E(and .1EE are installed in some systems1
*efore submitting their final pro3ect, they can start doing mini pro3ect fromndyear on%ards1
Balaji Institute of Technology and Science 5
8/10/2019 Lab Manual 16
6/95
Department of Computer Science and Engineering
M#SM 2Macro #ssembler3is installed in all the systems
tudents can eecute their assembly language programs using MAM1
MAM is 4ery useful students because %hen they eecute their
programs they can see contents of rocessor %egistersand ho%each instructionis being eecuted in the C+1
/ational /ose oft%are is installed in some systems
sing this soft%are, students can depict ML diagrams of their
pro3ects1
Softares installe! ", HH, &.?"16, MAM, 2II$+#F8, &++ and .2'
N+', /ational /ose1
Systems are pro$i!e! for stu!ents in the 4"4 ratio'
Systems are assigne! numbers an! same system is allotte! for
stu!ents hen they !o the lab'
Balaji Institute of Technology and Science
8/10/2019 Lab Manual 16
7/95
Department of Computer Science and Engineering
S(#)D#%D OE%#(I), %OCED+%E 5 SO
a) +planation on todayGs eperiment by the concerned faculty using 208>88'
co4ering the follo%ing aspects- 6 mins1
") Name of the eperiment>Aim
) oft%are>0ard%are reCuired
7) Algorithm
5) 'est .ata
") Valid data sets
) Limiting 4alue sets
7) $n4alid data sets
b) Writing of source program by the students 6 min1
c) ompiling and eecution of the program
"!! mins1
6riting of the e7periment in the Obser$ation Boo8-
'he students %ill %rite the todayGs eperiment in the 2bser4ation book as
per the follo%ing format-
a) Name of the eperiment>Aim
b) oft%are>0ard%are reCuired
c) Algorithm
d) ource 8rogram
e) 'est .ata
a1 Valid data sets
b1 Limiting 4alue sets
c1 $n4alid data sets
f) /esults for different data sets
g) Vi4a#Voc =uestions and Ans%ers
h) +rrors obser4ed (if any) during compilation>eecution
i) ignature of the Iaculty
Balaji Institute of Technology and Science !
8/10/2019 Lab Manual 16
8/95
Department of Computer Science and Engineering
,ui!elines to Stu!ents
+Cuipment in the lab for the use of student community1 tudents need to
maintain a proper decorum in the computer lab1 tudents must use the
eCuipment %ith care1 Any damage is caused is punishable1
tudents are reCuired to carry their obser4ation > programs book %ith
completed eercises %hile entering the lab1
tudents are supposed to occupy the machines allotted to them and are not
supposed to talk or make noise in the lab1 'he allocation is put up on thelab notice board1
Lab can be used in free time > lunch hours by the students %ho need to use
the systems should take prior permission from the lab in#charge1
Lab records need to be submitted on or before date of submission1
tudents are not supposed to use floppy disks
Balaji Institute of Technology and Science "
8/10/2019 Lab Manual 16
9/95
Department of Computer Science and Engineering
Ho to 6rite an! e7ecute s9l: pl;s9l comman!s;programs"
")1 2pen your oracle application by the follo%ing na4igation
tart#Jall programs#Joracle orahome1#Japplicationde4elopment#JsCl1
)1 You %ill be asked for user name, pass %ord and host stringYou ha4e to enter user name, pass %ord and host string as gi4en
by the administrator1 $t %ill be different from one user to another user1
7)1 pon successful login you %ill get =L prompt (=LJ)1
$n t%o %ays you can %rite your programs- a)1 directly at =L prompt
b)1 or in sCl editor1
$f you type your programs at sCl prompt then screen %ill look like follo%-
=LJ +L+' ename,empno,
sal from7 empK
%here and 7 are the line numbers and rest is the command >program
to eecute abo4e program>command you ha4e to press >G then enter1
0ere editing the program is some%hat difficultK if you %ant to edit the pre4ious
command then you ha4e to open sCl editor (by default it displays the sCl buffercontents)1 *y gi4ing edG at sCl prompt1(this is %hat $ mentioned as a second
method to type>enter the program)1in the sCl editor you can do all the formatting>editing>file operations directly byselecting menu options pro4ided by it1
'o eecute the program %hich sa4edK do the follo%ing
=LJ programname1sCl
2r=LJ /un programname1sCl
'hen press OG key and enter1
'his ho% %e can %rite, edit and eecute the sCl command and programs1
Al%ays you ha4e to sa4e your programs in your o%n logins1
Balaji Institute of Technology and Science #
8/10/2019 Lab Manual 16
10/95
8/10/2019 Lab Manual 16
11/95
Department of Computer Science and Engineering
a) reate the tables %ith the appropriate integrity constraintsb) $nsert around "! records in each of the tables
c) List all the student names %ith their membership numbersd) List all the issues for the current date %ith student and
*ook names
e) List the details of students %ho borro%ed book %hoseauthor is &.A'+
f) ;i4e a count of ho% many books ha4e been bought byeach student
g) ;i4e a list of books taken by student %ith studPno as 6
h) List the book details %hich are issued as of todayi) reate a 4ie% %hich lists out the issPno, iss Pdate,
studPname, book name3) reate a 4ie% %hich lists the daily issues#date %ise for the
last one %eek
= Database Schema for a Employee-pay scenario
employee(emp Database Schema for a /i!eo Library scenario
ustomer(custPno- integer,custPname- string)
Membership(Mem
8/10/2019 Lab Manual 16
12/95
Department of Computer Science and Engineering
cass
8/10/2019 Lab Manual 16
13/95
Department of Computer Science and Engineering
A imple programs using loop, %hile and for iterati4e controlstatement1
Write a program to check %hether the gi4en number isArmstrong or not
0 Write a program to generate all prime numbers belo% "!!1
4 Write a program to demonstrate the ;2'2 statement1
44 Write a program to demonstrate Utype and Uro%type attributes41 Write a program to demonstrate predefined eceptions
4= Write a program to demonstrate user defined eceptions
4> reate a cursor, %hich displays all employee numbers andnames from the +M8 table1
4? reate a cursor, %hich update the salaries of all employees asper the gi4en data1
4@ reate a cursor, %hich displays names of employees ha4ingsalary J 6!!!!1
4A reate a procedure to find re4erse of a gi4en number
4 reate a procedure to update the salaries of all employees asper the gi4en data
40 reate a procedure to demonstrate $N, 2' and $N2'parameters
1 reate a function to check %hether gi4en string is palindrome or
not1
14 reate a function to find sum of salaries of all employees
%orking in depart number "!1
11 reate a trigger before>after update on employee table for each
ro%>statement1
1= reate a trigger before>after delete on employee table for each
ro%>statement11> reate a trigger before>after insert on employee table for each
ro%>statement1
1? reate a Iorm to display employee details using =L
1@ reate a /eport to generate all employee annual salaries1
#!!itional rograms
S' )o )ame of the rogram
4 reate a form using Iorms Bi to display +mployee tabledata1
1 reate a Master>details relationship form %hichperform Add Ne%, earch, .elete, a4e and pdate on
the records
= ;enerate a report to calculate employeeGs salaries
Balaji Institute of Technology and Science $3
8/10/2019 Lab Manual 16
14/95
Department of Computer Science and Engineering
department %ise from employee table1
> reate a /eport to generate the details of employee
table including sum and a4erage salaries department
%ise1
Balaji Institute of Technology and Science $4
8/10/2019 Lab Manual 16
15/95
Department of Computer Science and Engineering
Bac8groun! (heory
2racle %orkgroup or ser4er is the largest selling /.*M product1it is estimated
that the combined sales of both these oracle database product account for aroud
'hese products are constantly undergoing change and e4ol4ing1 'he natural
language of this /.*M product is AN$ =L,8L>=L a superset of AN$=L1oracle
8/10/2019 Lab Manual 16
16/95
Department of Computer Science and Engineering
#lter table tablenameJ add(ne% colJdatatype(siEe),ne%
colJdatatype(siEe))K
E7"alter table emp add(sal number(:,))K
=' Dropping a column from a table'
Synta7"Alter table tablenameJ drop column colJK
E7"alter table emp drop column salK
>' Mo!ifying e7isting columns'
Synta7"
Alter table tablenameJ modify(colJne%datatypeJ(ne%siEeJ))K
E7"
alter table emp modify(ename 4archar("6))K
?' %enaming the tables
Synta7"
%enameoldtableJ to ne% tableJK
E7" rename emp to emp"K
@' truncating the tables'
Synta7"
(runcate tabletablenameJK
E7"trunc table emp"K
A' Destroying tables'
Synta7"Drop tabletablenameJK
E7"drop table empK
Balaji Institute of Technology and Science $
8/10/2019 Lab Manual 16
17/95
Department of Computer Science and Engineering
DML comman!s"
' Inserting Data into (ables" -once a table is created the most natural thingto do is load this table %ith data to be manipulated later1
Synta7"insert into tablenameJ (col"J,colJ) 4alues(epJ,epJ)K
0' Delete operations'
a3remo4e all ro%s
Synta7"delete from tablenameJK
b3remo4al of a specified ro%>sSynta7"
delete from tablenameJ %here conditionJK
4' +p!ating the contents of a table'
a3updating all ro%s
Synta7"pdate tablenameJ set colJRepJ,colJRepJK
b3updating seleted records1ynta-
pdate tablenameJ set colJRepJ,colJRepJ%here conditionJK
44' (ypes of !ata constrains'
a3not null constraint at column le4el1
Synta7"colJdatatypeJ(siEe)not null
b3uniCue constraint
Synta7"
niCue constraint at column le4el1
colJdatatypeJ(siEe)uniCueK
c3uniCue constraint at table le4el-
Synta7"
reate table tablename(colRformat,colRformat,uniCue(col"J,colJ)K
!3primary key constraint at column le4elSynta7"
colJdatatypeJ(siEe)primary keyK
Balaji Institute of Technology and Science $!
8/10/2019 Lab Manual 16
18/95
Department of Computer Science and Engineering
e3 primary key constraint at table le4el1Synta7"
reate table tablename(colRformat,colRformatprimary key(col"J,colJ)K
f3foreign key constraint at column le4el1Synta7"
colJdatatypeJ(siEeJ) references tablenameJcolJXK
g3foreign key constraint at table le4el
Synta7"foreign key(colJ,colJX)references tablenameJ(colJ,colJ)
h3check constraint
check constraint constraint at column le4el1
Synta7" colJdatatypeJ(siEe) check(logical epressionJ)
i3check constraint constraint at table le4el1Synta7"check(logical epressionJ)
Balaji Institute of Technology and Science $"
8/10/2019 Lab Manual 16
19/95
Department of Computer Science and Engineering
DL Comman!s"
41' /ieing !ata in the tables- # once data has been inserted into a table, the
net most logical operation %ould be to 4ie% %hat has been inserted1
a3all ro%s and all columns
Synta7"elect colJ to col nJ from tablenameK
elect from tablenameK
4=' *iltering table !ata- # %hile 4ie%ing data from a table, it is rare that all thedata from table %ill be reCuired each time1 0ence, sCl must gi4e us a method of
filtering out data that is not reCuired data1
a3elected columns and all ro%s-
Synta7"select col"J,colJ from tablenameJK
b3selected ro%s and all columns-Synta7"
select from tablenameJ %here conditionJK
c3selected columns and selected ro%s
Synta7"select col"J,colJ from tablenameJ %hereconditionJK
4>' Sorting !ata in a table'
Synta7"elect from tablenameJ order by col"J,colJ sortorderXJK
DCL comman!s"2racle pro4ides etensi4e feature in order to safeguard information stored in its
tables from unauthoraised 4ie%ing and damage1'he rights that allo% the user of
some or all oracle resources on the ser4er are called pri4ileges1
a3 ;rant pri4ileges using the ;/AN' statement
'he grant statement pro4ides 4arious types of access to database ob3ects such astables,4ie%s and seCuences and so on1
Synta7";/AN' ob3ect pri4ilegesJ
2N ob3ectnameJ'2usernameJ
Balaji Institute of Technology and Science $#
8/10/2019 Lab Manual 16
20/95
Department of Computer Science and Engineering
W$'0 ;/AN' 28'$2NXK
b3/eoke permissions using the /+V2?+ statement-
'he /+V2?+ statement is used to deny the ;rant gi4en on an ob3ect1
Synta7"/+V2?+ob3ect pri4ilegeJ
2NI/2Muser nameJK
Balaji Institute of Technology and Science 2%
8/10/2019 Lab Manual 16
21/95
Department of Computer Science and Engineering
Solutions for programs 2.)(+ Syllabus3
4' Database Schema for a customer-sale scenario
ustomer(Cust i! " integer: custPname- string)$tem(item
8/10/2019 Lab Manual 16
22/95
Department of Computer Science and Engineering
#im- reate the tables %ith the appropriate integrity constraints and $nsertaround "! records in each of the tables
H6;S6 re9uirements"
8rocessor - AM. Athelon D "1B: ;0E
/AM - 6B M*
0ard .isk - 5! ;*
oft%are - 2/AL+
=LJ create table customer" (custPid number(6) primary key, custPname4archar("6))K
Output"'able created1
=LJ desc customer"K
Output"
Name NullZ 'ype######################################### ######## ################
'P$. N2' NLL NM*+/(6)
'PNAM+ VA/0A/("6)
/ali! (est Data
b3 =LJ insert into customer" 4alues([custid,\[custname\)K
=LJ select from customer"K
Output"'P$. 'PNAM+########## ###############
"!! ramu "!" kamal
"! ra3u
"!7 ra3u sundaram "!5 la%rence
=LJ create table item(itemPid number(5) primary key,
itemPname 4archar("6),price number(B,))K=LJ dsec item
Output"Name NullZ 'ype
ustPid N2' NLL NM*+/(5)$temPname VA/0A/("6)
8/$+ NM*+/(B,)
Balaji Institute of Technology and Science 22
8/10/2019 Lab Manual 16
23/95
Department of Computer Science and Engineering
=LJinsert into item 4alues([itemPid,G[itemPnameG,[price)K
=LJ select from itemK
Output"$'+MP$. $'+MPNAM+ 8/$+
11775 geera B16
567 corn soup 751B6"5 lays chips !
567" set%et @@1@@
7"@ duracell 5616
=LJcreate table sale(billPno number(6) primary key,billPdate date, custPidnumber(6) references customer(custPid), itemPid number(5) references
item(itemPid),CtyPsold number(5))K
Out put- 'able reated1
=LJdsec sale
Output" Name NullZ 'ype
11*$LLPN2 N2' NLL NM*+/(5)
*$LLP.A'+ .A'+
'P$. NM*+/(6)$'+MP$. NM*+/(5)
='YP2L. NM*+/(5)
=LJinsert into ale 4alues([billPno, G[billPdateG, [custPid, [itemPid, [CtyPsold)K
=LJselect from saleKOutput"
*$LLPN2 *$LLP.A'+ 'P$. $'+MP$. ='YP2L.111
"56! !5#&AN#!B "!! "5
"56" !5#&AN#!B "!" 7"@ ""56 !5#&AN#!B "!7 567"
"567 !5#&AN#!B "! 775 7"565 !5#&AN#!B "!5 567 7
c3 List all the bills for the current date %ith the customer names and itemnumbers
=LJ select c1custname, i1itemid, s1billno from customer c, item $, sale s%here c1custidRs1custid and
Balaji Institute of Technology and Science 23
8/10/2019 Lab Manual 16
24/95
Department of Computer Science and Engineering
s1billdateRtoPchar(sysdate)K
'NAM+ $'+M$. *$LLN2
############# ######### #########&ohn 6!!" 77
!3 List the total *ill details %ith the Cuantity sold, price of the item and the
final amount=LJ select i1price, s1Cty,(i1prices1Cty) total from item $, sale s %here
i1itemidRs1itemidK
8/$+ ='Y '2'AL
####### ##### ########"! 5!
! 7 B!
6 "!
"! " "!76! 5 "5!!
e3List the details of the customer %ho ha4e bought a product %hich has apriceJ!!
=LJ select c1custid, c1custname from customer c, sale s, item i %here
i1priceJ!! andc1custidRs1custid and i1itemidRs1itemidK
'$. 'NAM+
######### ##############5 duffy
f3 ;i4e a count of ho% many products ha4e been bought by each customer=LJ select custid, count(itemid) from sale group by custidK
'$. 2N'($'+M$.)########## #####################
" 7 "
5 "
6 "
g3;i4e a list of products bought by a customer ha4ing custPid as 6=LJ select i1itemname from item i, sale s %here s1custidR6 and i1itemid#
s1itemidK
$'+MNAM+
##############8ens
Balaji Institute of Technology and Science 24
8/10/2019 Lab Manual 16
25/95
Department of Computer Science and Engineering
h3 List the item details %hich are sold as of today
=LJ select i1itemid, i1itemname from item $, sale s %here
i1itemidRs1itemidand s1billdateRtoPchar(sysdate)K
$'+M$. $'+MNAM+
######### #############
"75 pencil
i3 reate a 4ie% %hich lists out the billPno, billPdate, custPid,itemPid, price, CtyPsold, amount
=LJcreate 4ie% cust as (select s1billno, s1billdate, c1custid, i1 iitemid,
i1price, s1Cty from customer c,sale s item $ %here c1custidRs1custid
and i1iemidRs1itemid)K
4ie% created1
=LJselect from custK
*$LLN2 *$LL.A'+ '$. $'+M$. 8/$+ ='Y
757 "#&AN#!B 7 755 "! 555 !#I+*#!B " 756B ! 7
77 "7#MA/#!B " "75 6 757 "!#MA/ 6 6!!" "! ""77" ""#MA/#!B 5 :B::B 76! 5
3reate a 4ie% %hich lists the daily sales date %ise for the last one
%eek
/i$a-/oce"
="1 What is =LZAns- tructured =uery Language
2. What is database?
A database is a logically coherent collection of data %ith some inherent
meaning, representing some aspect of real %orld and %hich is designed, built
and populated %ith data for a specific purpose1
Balaji Institute of Technology and Science 25
8/10/2019 Lab Manual 16
26/95
Department of Computer Science and Engineering
3. What is DBMS?
$t is a collection of programs that enables user to create and maintain adatabase1 $n other %ords it is general#purpose soft%are that pro4ides the users
%ith the processes of defining, constructing and manipulating the database for4arious applications1
4. What is a Database system?'he database and .*M soft%are together is called as .atabase system1
5. d!antages of DBMS?
/edundancy is controlled1
nauthorised access is restricted1
8ro4iding multiple user interfaces1
+nforcing integrity constraints1
8ro4iding backup and reco4ery1
". Disad!antage in #ile $rocessing System? .ata redundancy [ inconsistency1
.ifficult in accessing data1
.ata isolation1
.ata integrity1
oncurrent access is not possible1
ecurity 8roblems1
Balaji Institute of Technology and Science 2
8/10/2019 Lab Manual 16
27/95
Department of Computer Science and Engineering
1' Database Schema for a Stu!ent Library scenario
tudent(Stu!
8/10/2019 Lab Manual 16
28/95
Department of Computer Science and Engineering
#IM" reate the tables %ith the appropriate integrity constraints
$nsert around "! records in each of the tables
H6;S6 re9uirements"
8rocessor - AM. Athelon D "1B: ;0E
/AM - 6B M*0ard .isk - 5! ;*
oft%are - 2racle
=LJcreate table student(studPno number(6) primary key,studPname4archar("6))K
=LJdesc studentK Name NullZ 'ype
11'.PN2 N2' NLL NM*+/(6)
'.PNAM+ VA/A0/("6)
/ali! (est Data"
=LJinsert into student 4alues([studPno,G[studPnameG)K
=LJselect from studentK
'.PN2 '.PNAM+
11111111111111111111111111111111111111111111111111111111111111111111
6!< 0A/$06"7 *ALA&$
6"< /A?+0
65 8AVAN675 &2Y+
=LJcreate table membership(memPno number(6) primary key,studPno
number(6) references student(stud)no))K
=LJdsec membershipK
Name NullZ 'ype1
M+MPN2 N2' NLL NM*+/(6)
'.PN2 NM*+/(6)
=LJinsert into membership 4alues([memPno,[studPno)K
+nter 4alue for memPno-655!
+nter 4alue for studPno-6"!Balaji Institute of Technology and Science 2"
8/10/2019 Lab Manual 16
29/95
Department of Computer Science and Engineering
old "-insert into membership 4alues([memPno,[studPno)
ne% "-insert into membership 4alues(655!,6"!)insert into membership 4alues(655!,6"!)
Errors Obser$e!"
+//2/ at line "-2/A#!@"-integrity constraint(0A/$01YP!!:5)4iolated#primary key not
found
=LJselect from membershipK
M+MPN2 '.PN211
655! 6"7655" 6!' Database Schema for a /i!eo Library scenario
ustomer(custPno- integer,custPname- string)
Membership(Mem
8/10/2019 Lab Manual 16
40/95
Department of Computer Science and Engineering
#IM"reate the tables %ith the appropriate integrity constraints $nsert around "! records in each of the tables
H6;S6 re9uirements"
8rocessor - AM. Athelon D "1B: ;0E
/AM - 6B M*0ard .isk - 5! ;*
oft%are - 2racle
=LJcreate table customer(custPno number(6) primary key,custPname
4archar(!))K
=LJdesc customerK
Name NullZ 'ype11'PN2 N2' NLL NM*+/(6)
'PNAM+ VA/0A/(!)
/ali! (est Data"
=LJinsert into customer 4alues([custPno,G[custPnameG)K
=LJselect from customerK
'PN2 'PNAM+1
6! scott
6" pandey6 4arshney
67 naidu65 bhimbra
=LJcreate table membership(memPno number(6) primary key,custPnonumber(6) references customer(custPno))K
=LJdsec membershipKName NullZ 'ype
111M+MPN2 N2' NLL NM*+/(6)
'PN2 NM*+/(6)
=LJinsert into memship 4alues([memPno,[custPno)K
=LJselect from memshipK
Balaji Institute of Technology and Science 4%
8/10/2019 Lab Manual 16
41/95
Department of Computer Science and Engineering
M+MPN2 'PN2
@! 6!
@
8/10/2019 Lab Manual 16
42/95
Department of Computer Science and Engineering
!:#&AN#!B @! "
7 "!#&AN#!! @
8/10/2019 Lab Manual 16
43/95
Department of Computer Science and Engineering
An entity set may not ha4e sufficient attributes to form a primary key, and
its primary key compromises of its partial key and primary key of its parententity, then it is said to be Weak +ntity set1
2%. What is an attribute?
$t is a particular property, %hich describes the entity1
22. What is a -elation Schema and a -elation?
A relation chema denoted by /(A", A, , An) is made up of the relationname / and the list of attributes Ai that it contains1 A relation is defined as a set
of tuples1 Let r be the relation %hich contains set tuples (t", t, t7, 111, tn)1 +ach
tuple is an ordered list of n#4alues tR(4",4, 111, 4n)1
23. What is degree of a -elation?$t is the number of attribute of its relation schema1
24. What is -elationship?
$t is an association among t%o or more entities1
25. What is -elationship set?
'he collection (or set) of similar relationships1
?'Database Schema for a stu!ent-Lab scenario
tudent(stu!
8/10/2019 Lab Manual 16
44/95
Department of Computer Science and Engineering
f) ;i4e a machine allotment etails of the studPno 6 %ith his personal and
class detailsg) ount for ho% many machines ha4e been allocatedin Lab
8/10/2019 Lab Manual 16
45/95
Department of Computer Science and Engineering
#IM"reate the tables %ith the appropriate integrity constraints
$nsert around "! records in each of the tables
H6;S6 re9uirements"
8rocessor - AM. Athelon D "1B: ;0E
/AM - 6B M*0ard .isk - 5! ;*
oft%are - 2racle
=LJcreate table stu(studPno number(6) primary key,studPnam4archar(!),class 4archar(!))K
=LJ desc stuK
Name nullZ 'ype
'.PN2 N2' NLL NM*+/(6)'.PNAM VA/0A/(!)
LA VA/0A/(!)
/ali! Data Sets"
=LJ insert into stu 4alues([studPno,G[studPnamG,G[classG)K
=LJ select from stuK
'.PN2 '.PNAM LA
7@ L+2N +75 V$?A $'"< MA'0+W ++
< 0AN+N M+05 AL+F$ +++
=LJ reate table class (class 4archar(!), descript 4archar("!))K=LJ .escribe classK
Name null type
LA VA/0A/("!)
.+/$8' VA/0A/(!)
=LJ create table lab(matchPno number(6), labPno number(6), description4archar(!))K
=LJ desc labK
Balaji Institute of Technology and Science 45
8/10/2019 Lab Manual 16
46/95
Department of Computer Science and Engineering
Name null type
MA0PN2 N2' NLL NM*+/(6)LA*PN2 NM*+/(6)
.+/$8'$2N VA/0A/(!)
=LJ insert into lab 4alues([machPno,[labPno,G[descriptionG)K
=LJ select from labK
MA'0PN2 LA*PN2 .+/$8'$2N
############### ######### ####################
7 : physics:< chemistry
8/10/2019 Lab Manual 16
47/95
Department of Computer Science and Engineering
'.NAM+ MA0N211
A*0$&++' "?ALYAN
A0W$N 7
A/?A 5A/V$N. 6
d) List the total number of lab allotments day %ise
=LJselect l1machno,l1descrip,a1day from lab l,allotment a %here
a1machnoRl1machnoK
MA0N2 .+/$8 .AY
" N$F M2N.AY N$F '+.AY7 F8 W+.N+.AY
5 W$N.2W '0/.AY6 M+ I/$.AY
e) ;i4e a count of ho% many machines ha4e been allocated to the $'G class
=LJselect count(machno)from allotment %here studno in(select studno fromstudent" %here classRG$'G)K
2N' (MA0N2)11
"
f) ;i4e a machine allotment etails of the studPno 6 %ith his personal and
class details
=LJselect a1studno,a1machno,s1studname,s1class from allotment a,student"s %here a1studnoRs1studno and a1studnoR6!7K
'.N2 MA0N2 '.NAM+ LA
6!7 6 A/V$N. +
g) ount for ho% many machines ha4e been allocatedin Lab
8/10/2019 Lab Manual 16
48/95
Department of Computer Science and Engineering
=LJselect count(studno) Sallocated students in the labsT,class from student"%here studno in(select studno from allotment) group by classK
allocated students in the lab LA
+ " ++
" +++ " $'
i) reate a 4ie% %hich lists out the studPno, studPname, machPno, labPno,dayof%eek
3) reate a 4ie% %hich lists the machine allotment details for S'hursdayT
/i$a-/ice"
2". What is -elationship type?
/elationship type defines a set of associations or a relationship set amonga gi4en set of entity types1
2. What is degree of -elationship type?$t is the number of entity type participating1
25. What is DD' :Data Definition 'anguage;?
A data base schema is specifies by a set of definitions epressed by a
special language called ..L1
2". What is (D' :(ie) Definition 'anguage;?$t specifies user 4ie%s and their mappings to the conceptual schema1
2. What is SD' :Storage Definition 'anguage;?'his language is to specify the internal schema1 'his language may specify
the mapping bet%een t%o schemas1
26. What is Data Storage Definition 'anguage?
'he storage structures and access methods used by database system arespecified by a set of definition in a special type of ..L called data storage#
definition language1
27. What is DM' :Data Manipulation 'anguage;?
Balaji Institute of Technology and Science 4"
8/10/2019 Lab Manual 16
49/95
Department of Computer Science and Engineering
'his language that enable user to access or manipulate data as organised
by appropriate data model1 $rocedural DM' or 'o) le!el& .ML reCuires a user to specify %hat data are
needed and ho% to get those data1 1on$rocedural DM' or 0igh le!el& .ML reCuires a user to specify %hat data
are needed %ithout specifying ho% to get those data1
3%. What is DM'
8/10/2019 Lab Manual 16
50/95
Department of Computer Science and Engineering
@3' 6rite a program to fin! largest number from the gi$enthree numbers'
#im" 'o find largest number from the gi4en three numbers1
H6;S6 re9uirements"8rocessor - AM. Athelon D "1B: ;0E
/AM - 6B M*
0ard .isk - 5! ;*
oft%are - 2racle, 8l=L
#lgorithm"
tep "- .eclare the 4ariable A, *, and 1
tep - tore the 4alid data1tep 7- ompare 4ariable A %ith * and A %ith
tep 5- $f the 4alue stored in 4ariable A is big, it displays SA is *igT1 ($Iconditional statement should be used)
tep 6- ompare 4ariable * %ith tep B- $f the 4alue stored in 4ariable * is big, it displays S* is *igT1
tep :- other %ise it displays S is *igT
.eclare
A numberK
* numberK
numberK
*egin
A-R[aK
*-R[bK
-R[cK
$f a J b [[ aJ c then
.bmsPoutput1putPline( A is big )K
+lse
Balaji Institute of Technology and Science 5%
8/10/2019 Lab Manual 16
51/95
Department of Computer Science and Engineering
$f( bJc [[ bJ a ) then
.bmsPoutput1putPline( * is big )K
+lse
.bmsPoutput1putPline( is big )K
+nd ifK
+nd ifK
+ndK
/ali! Data Sets"
+nter the 4alue of a-
"+nter the 4alue of b-
+nter the 4alue of c-
7
O+(+("
is big
In$ali! Data sets "
+nter the 4alue of a-
y+nter the 4alue of b-
+nter the 4alue of c-a
Output"
$n4alid data types1
/i$a-/ice"
7"1 What is 8l#=L Z
8rocedural Language tructured =uery Language
32. What is =uery e!aluation engine?
$t eecutes lo%#le4el instruction generated by compiler1
Balaji Institute of Technology and Science 5$
8/10/2019 Lab Manual 16
52/95
Department of Computer Science and Engineering
33. What is DD' ,nterpreter?
$t interprets ..L statements and record them in tables containingmetadata1
34. What is -ecordatatime?
'he Lo% le4el or 8rocedural .ML can specify and retrie4e each record from
a set of records1 'his retrie4e of a record is said to be /ecord#at#a#time1
35. What is Setatatime or Setoriented?'he 0igh le4el or Non#procedural .ML can specify and retrie4e many
records in a single .ML statement1 'his retrie4e of a record is said to be et#at#a#
time or et#oriented1
3". What is -elational lgebra?$t is procedural Cuery language1 $t consists of a set of operations that take
one or t%o relations as input and produce a ne% relation1
3. What is -elational
8/10/2019 Lab Manual 16
53/95
Department of Computer Science and Engineering
A3' Simple programs using loop: hile an! for iterati$econtrol statement'
a3 'o generate first "! natural numbers using loop: hileand for1
#IM"'o generate first "! natural numbers using loop, %hile and for1
H6;S6 re9uirements"
8rocessor - AM. Athelon D "1B: ;0E
/AM - 6B M*
0ard .isk - 5! ;*
oft%are - 2racle, 8l=L
#lgorithm"
tep "- .eclare the 4ariable $1tep - tore the 4alid data " in $1
tep 7- se LOOstatementtep 5- .isplay the first 4alue1
tep 6- $ncrement the 4alue of $ by " 4alue1
tep B- check the 4alue up to "! no1 and repeat the looptep :- $f condition eceeds the gi4en 4alue "!, the loop %ill be
terminated1
; using loop statement ;
.eclare
$ numberK
*egin
$-R"K
Loop
.bmsPoutput1putPline($)K
$-R$H"K
+it %hen $J"!K
+nd loopK
Balaji Institute of Technology and Science 53
8/10/2019 Lab Manual 16
54/95
Department of Computer Science and Engineering
+ndK
#lgorithm" for 6HILE loop
tep "- .eclare the 4ariable $1
tep - tore the 4alid data " in $1tep 7- se 6HILEstatement
tep 5- heck the 4alue of $ %ith 4alue "!1
tep 6- if the 4alue of $ reached to "! the loop %ill be terminatedtep B- other%ise display 4alue of $
tep :- increment the net 4alue of $ using $R$H"1
; using hile ;
.eclare
$ numberK
*egin
$-R"K
While ($R"!)
loop
.bmsPoutput1putPline($)K
$-R$H"K
+nd loopK
+ndK
Balaji Institute of Technology and Science 54
8/10/2019 Lab Manual 16
55/95
Department of Computer Science and Engineering
#lgorithm"
tep "- .eclare the 4ariable $1tep - tore the 4alue " in 4ar1 $1
tep 7- se *or LOOstatementtep 5- .isplay the first 4alue of $1
tep 6- $ncrement the 4alue of $ by " 4alue1
tep B- check the 4alue up to "! no1 and repeat the looptep :- if the loop eceeds the 4alue "! then the loop %ill be terminated1
; using for loop;
*egin
Ior $ in "11"!
loop
.bmsPoutput1putPline($)K
+nd loopK
+ndK
/ali! (est Data-
O+(+(
"
7
56
B:
ation?
$t is a process of analysing the gi4en relation schemas based on theirIunctional .ependencies (I.s) and primary key to achie4e the properties
MinimiEing redundancy
MinimiEing insertion, deletion and update anomalies1
48. What is #unctional Dependency?A Iunctional dependency is denoted by F Y bet%een t%o sets of
attributes F and Y that are subsets of / specifies a constraint on the possibletuple that can form a relation state r of /1 'he constraint is for any t%o tuples t"
and t in r if t"FX R tFX then they ha4e t"YX R tYX1 'his means the 4alue ofF component of a tuple uniCuely determines the 4alue of component Y1
4%. When is a functional dependency # said to be minimal? +4ery dependency in I has a single attribute for its right hand side1
We cannot replace any dependency F A in I %ith a dependency Y A %here
Y is a proper subset of F and still ha4e a set of dependency that is eCui4alentto I1
We cannot remo4e any dependency from I and still ha4e set of dependency
that is eCui4alent to I1
42. What is Multi!alued dependency?Multi4alued dependency denoted by F Y specified on relation
schema /, %here F and Y are both subsets of /, specifies the follo%ing constraint
on any relation r of /- if t%o tuples t" and t eist in r such that t"FX R tFXthen t7 and t5 should also eist in r %ith the follo%ing properties t7X R t5FX R t"FX R tFX
t7YX R t"YX and t5YX R tYX
t7]X R t]X and t5]X R t"]X
%here ] R (/#(F Y)) X
43. What is 'ossless /oin property?
$t guarantees that the spurious tuple generation does not occur %ithrespect to relation schemas after decomposition1
Balaji Institute of Technology and Science 5
8/10/2019 Lab Manual 16
57/95
Department of Computer Science and Engineering
Balaji Institute of Technology and Science 5!
8/10/2019 Lab Manual 16
58/95
Department of Computer Science and Engineering
' rogram to chec8 hether gi$en number is #rmstrongor not'
#IM" to check %hether gi4en number is Armstrong or not1
H6;S6 re9uirements"8rocessor - AM. Athelon D "1B: ;0E
/AM - 6B M*
0ard .isk - 5! ;*
oft%are - 2racle, 8l#=L
#lgorithm"
tep "- .eclare the 4ariable N, , . and .81
tep - tore the 4alue in 4ar1 N and 4ar1 .811tep 7- check for the 4alue of N, %hich is not eCual to !1
tep 5- di4ide 4alue stored in N by "! and store it 4ar1 .1 (.RnU"!)1tep 6- the reminder %ill be multiply 7 times and store it in Var1 1
tep B- 'he coefficient %ill be calculated using IL22/ function1 And store itin 4ar1 N1
tep :- repeat the teps 7, 5, 6, and B till loop %ill be terminated1
tep
8/10/2019 Lab Manual 16
59/95
Department of Computer Science and Engineering
-RsH(...)K
N-Rfloor(n>"!)K
+nd loopK
$f (.8R) then
.*MPoutput1putPline(number is armstrongG)K
+lse
.*MPoutput1putPline(number is not armstrongG)K
+nd ifK
+ndK
(est /ali! Data Set"
+nter 4alue of n
"67
O+(+("
number is Armstrong1
/i$a-/ice "
44. What is 1 NF (Normal Form)?The domain of attri&ute must include only atomic 'simple( indi)isi&le* )alues+
45. What is Fully Functional dependency?It is &ased on concept of full functional dependency+ , functional dependency - . is full
functional dependency if remo)al of any attri&ute , from - means that the dependency does not hold
any more+
4". What is 2NF?, relation schema / is in 201 if it is in $01 and e)ery nonprime attri&ute , in / is fully
functionally dependent on primary ey+
4. What is 3NF?, relation schema / is in 301 if it is in 201 and for e)ery 1D - , either of the folloing is
true - is a Superey of /+
, is a prime attri&ute of /+
In other ords( if e)ery non prime attri&ute is nontransiti)ely dependent on primary ey+
Balaji Institute of Technology and Science 5#
8/10/2019 Lab Manual 16
60/95
Department of Computer Science and Engineering
46. What is BCNF (Boyce-Codd Normal Form)?, relation schema / is in BC01 if it is in 301 and satisfies an additional constraint that for
e)ery 1D - ,( - must &e a candidate ey+
47. What is 4NF?, relation schema / is said to &e in 401 if for e)ery ulti)alued dependency - .
that holds o)er /( one of folloing is true
- is su&set or e6ual to 'or* -. 7 /+ - is a super ey+
Balaji Institute of Technology and Science %
8/10/2019 Lab Manual 16
61/95
Department of Computer Science and Engineering
0' 6rite a program to generate all prime numbers belo4'
#IM- to generate all prime numbers belo% "!!1
H6;S6 re9uirements"8rocessor - AM. Athelon D "1B: ;0E
/AM - 6B M*
0ard .isk - 5! ;*
oft%are - 2racle, 8l=L
.eclare
$ numberK
& numberK
numberK
*egin
While(iR"!!)
Loop
-R!K&-R"K
While(3Ri)
Loop
$f(floor(iU3)R!) then
-R H"K
+nd ifK
&-R3H"K
+nd loopK
$f(cR) then
.bmsPoutput1putPline(i)K
Balaji Institute of Technology and Science $
8/10/2019 Lab Manual 16
62/95
Department of Computer Science and Engineering
+nd ifK
+ndloopK+ndK
/ali! (est Data
O+(+("
7
6
:
""
1
1
@@
/i$a-/ice"
58. What is 5NF?
, /elation schema / is said to &e 501 if for e)ery join dependency 8/$( /2( +++( /n9 thatholds /( one the folloing is true /i 7 / for some i+
The join dependency is implied &y the set of 1D( o)er / in hich the left side is ey of /+
51 What is !omain-"ey Normal Form?, relation is said to &e in D:01 if all constraints and dependencies that should hold on the the
constraint can &e enforced &y simply enforcing the domain constraint and ey constraint on the
relation+
52 What are partial# alternate## arti$icial# compound and natural %ey?
&artial "ey'
It is a set of attri&utes that can uni6uely identify ea entities and that are related to sameoner entity+ It is sometime called as Discriminator+
lternate "ey'
,ll Candidate :eys e;cluding the
8/10/2019 Lab Manual 16
63/95
Department of Computer Science and Engineering
If no single data element uni6uely identifies occurrences ithin a construct( thencom&ining multiple elements to create a uni6ue identifier for the construct is non as creating a
compound ey+
Natural"ey:
>hen one of the data elements stored ithin a construct is utili?ed as the primary ey(
then it is called the natural ey+
53 What is indein* and +hat are the di$$erent %inds o$ indein*?Inde;ing is a techni6ue for determining ho 6uicly specific data can &e found+
Types= Binary search style inde;ing
BTree inde;ing
In)erted list inde;ing
emory resident ta&le
Ta&le inde;ing
Balaji Institute of Technology and Science 3
8/10/2019 Lab Manual 16
64/95
Department of Computer Science and Engineering
4' 6rite a program to !emonstrate the ,O(O statement'
#IM- to demonstrate the ;2'2 statement
H6;S6 re9uirements"
8rocessor - AM. Athelon D "1B: ;0E
/AM - 6B M*
0ard .isk - 5! ;*
oft%are - 2racle, 8l=L
.eclare
$ numberK
*egin
$-R"K
$f(iJR!) then
;2'2 hereK
+lse
.bmsPoutput1putPline( $ is negati4eG)K
+nd ifK
hereJJ
.bmsPoutput1putPline( $ is positi4eG)K
+ndK
/ali! (est Data
O+(+("
$ is positi4e
/i$a-/ice"
54 What is system catalo* or catalo* relation? ,o+ is etter %no+n as?
Balaji Institute of Technology and Science 4
8/10/2019 Lab Manual 16
65/95
Department of Computer Science and Engineering
, /DBS maintains a description of all the data that it contains( information a&out e)eryrelation and inde; that it contains+ This information is stored in a collection of relations maintained &y
the system called metadata+ It is also called data dictionary+
55 What is meant y .uery optimi/ation?
The phase that identifies an efficient e;ecution plan for e)aluating a 6uery that has the least
estimated cost is referred to as 6uery optimi?ation+
50 What is oin dependency and inclusion dependency?
oin!ependency'
, @oin dependency is generali?ation of ulti)alued dependency+, @D 8/$(/2( +++( /n9 is said to hold o)er a relation / if /$( /2( /3( +++( /n is a losslessjoin decomposition of / +
There is no set of sound and complete inference rules for @D+
nclusion!ependency',n Inclusion Dependency is a statement of the form that some columns of a relation are
contained in other columns+ , foreign ey constraint is an e;ample of inclusion dependency+
5 What is duraility in !B6?
Ance the DBS informs the user that a transaction has successfully completed( its effectsshould persist e)en if the system crashes &efore all its changes are reflected on dis+ This property is
called dura&ility+
57 What do you mean y atomicity and a**re*ation?
tomicity'Either all actions are carried out or none are+ sers should not ha)e to orry a&out the
effect of incomplete transactions+ DBS ensures this &y undoing the actions of incomplete
transactions+**re*ation'
, concept hich is used to model a relationship &eteen a collection of entities and
relationships+ It is used hen e need to e;press a relationship among relationships+
58 What is a &hantom !eadloc%?
In distri&uted deadloc detection( the delay in propagating local information might cause the
deadloc detection algorithms to identify deadlocs that do not really e;ist+ Such situations are calledphantom deadlocs and they lead to unnecessary a&orts+
09 What is a chec%point and When does it occur?, Checpoint is lie a snapshot of the DBS state+ By taing checpoints( the DBS can
reduce the amount of or to &e done during restart in the e)ent of su&se6uent crashes+
Balaji Institute of Technology and Science 5
8/10/2019 Lab Manual 16
66/95
Department of Computer Science and Engineering
44' 6rite a program to !emonstrate type an! rotypeattributes
#IM- to demonstrate Utype and Uro%type attributes
H6;S6 re9uirements"8rocessor - AM. Athelon D "1B: ;0E
/AM - 6B M*
0ard .isk - 5! ;*
oft%are - 2racle, 8l=L
.eclare
MyP+mpno emp1empnoUtypeK
MyP+name emp1enameUtypeKMyP+mpro% empUro%typeK
No numberK
*egin
No-R[noK
elect empno,ename into myPempno,myPename from emp %hereempnoRnoK
$f(=lUro%countR") then
.bmsPoutput1putPline(empno isG __ myPempno __ ename is __
myPename)K
+lse
.bmsPoutput1putPline( errorG)K
+nd ifK
elect into myPempro% from emp %here empnoRnoK
$f(=lUro%countR") then
.bmsPoutput1putPline(empno isG __ myPempro%1empno __ ename is __
myPempro%1ename)K
+lse
Balaji Institute of Technology and Science
8/10/2019 Lab Manual 16
67/95
Department of Computer Science and Engineering
.bmsPoutput1putPline( errorG)K
+nd ifK
+ndK
/ali! (est Data
+nter the 4alue for no-
::
8/10/2019 Lab Manual 16
68/95
Department of Computer Science and Engineering
, correlated su&6uery can &e easily identified if it contains any references to the parentsu&6uery columns in its >E/E clause+ Columns from the su&6uery cannot &e referenced anyhere
else in the parent 6uery+ The folloing e;ample demonstrates a noncorrelated su&6uery+
E+g+ Select 1rom CST >here F$%G%3G$##%F I0 'Select AD,TE 1rom A/DE/ >hereCST+C0 7 A/DE/+C0*
0 What are the primiti;e operations common to all record mana*ement systems?
,ddition( deletion and modification+
Balaji Institute of Technology and Science "
8/10/2019 Lab Manual 16
69/95
Department of Computer Science and Engineering
41' 6rite a program to !emonstrate pre!efine! e7ceptions
#IM- to demonstrate predefined eceptions
H6;S6 re9uirements"
8rocessor - AM. Athelon D "1B: ;0E
/AM - 6B M*
0ard .isk - 5! ;*
oft%are - 2racle, 8l=L
.eclare
A number
* numberK
numberK
*egin
A-R[aK
*-R[bK
-Ra>bK
.bmsPoutput1putPline(di4ision is __ )K
+ception
$f (]+/2P.$V$.+) then
.bmsPoutput1putPline(b could not be EeroG)K
+nd ifK
+ndK
/ali! (est Data"
+nter the 4alue for a-
"!
+nter the 4alue for b-
Balaji Institute of Technology and Science #
8/10/2019 Lab Manual 16
70/95
Department of Computer Science and Engineering
!
O+(+("
b could not be Eero
/i$a-/ice"
07 Name the u$$er in +hich all the commands that are typed in are stored
EditBuffer
08 What are the unary operations in
Balaji Institute of Technology and Science !%
8/10/2019 Lab Manual 16
71/95
Department of Computer Science and Engineering
8rocessor - AM. Athelon D "1B: ;0E
/AM - 6B M*
0ard .isk - 5! ;*
oft%are - 2racle, 8l=L
.eclare
A number
* numberK
numberK
Mydi4idePEero +F+8'$2NK
*egin
A-R[aK
*-R[bK
$f(*R!) then
/aise Mydi4idePEeroK
else
-Ra>bK
.bmsPoutput1putPline(di4ision is __ )K
+nd ifK
+ception
$f (mydi4idePEero) then
.bmsPoutput1putPline(b could not be EeroG)K
+nd ifK
+ndK
/ali! (est Data"
+nter the 4alue for a-
Balaji Institute of Technology and Science !$
8/10/2019 Lab Manual 16
72/95
Department of Computer Science and Engineering
"!
+nter the 4alue for b-
!
O+(+("
b could not be Eero
/i$a-/ice"
5 Not only
determines an optimal access path to store or retrie)e the data
0 ,o+ do you communicate +ith an riter*(AW
8/10/2019 Lab Manual 16
73/95
Department of Computer Science and Engineering
Balaji Institute of Technology and Science !3
8/10/2019 Lab Manual 16
74/95
Department of Computer Science and Engineering
4?' Create a Cursor hich up!ate the salaries of an Employeeas follos'
"1 if sal"!!!then update the salary to "6!!1
1 if salJR"!!! and !!! then update the salary to 6!!1
71 if salJR!!! and R7!!! then update the salary to 5!!!1
And also count the no1of records ha4e been updated1>
H6;S6 re9uirements"
8rocessor - AM. Athelon D "1B: ;0E
/AM - 6B M*
0ard .isk - 5! ;*
oft%are - 2racle, 8l=L
.eclare
ursor myPcur is select empno,sal from empK
Fno emp1empnoUtypeKFsal emp1salUtypeK
numberK
*egin
2pen myPcurK
-R!K
Loop
Ietch myPcur into no,salK
$f(sal"!!!) then
pdate emp set salR7!!! %here empnoRnoK
-RcH"K
+lse if(salJR!!!) and sa7!!!) then
Balaji Institute of Technology and Science !4
8/10/2019 Lab Manual 16
75/95
Department of Computer Science and Engineering
pdate emp set salR5!!! %here empnoRnoK
-RcH"K
+nd ifK
+nd ifK
+it %hen myPcurUN2'I2N. K
+nd loopK
lose myPcurK
.bmaPoutput1putPline(c__Grecords ha4e been successfully updatedG)K
+ndK
ClJa1sClK
records ha4e been successfully updated
pl>sCl procedure successfully completed1
/ali! (est Data
*efore eecuting the cursor, the records in emp table as follo%s
ClJselect from empK
O+(+("
+M8N2 +NAM+ &2* M;/ 0$/+.A'+ AL 2MM. +8'N2
#################################################################
:7B@ M$'0 L+/? :@! ":#.+#
:5@@ ALL+N AL+MAN :B@< !#I+*#
8/10/2019 Lab Manual 16
76/95
Department of Computer Science and Engineering
:B65 MA/'$N AL+MAN :B@<
8/10/2019 Lab Manual 16
77/95
Department of Computer Science and Engineering
72 What is ID is a uni6ue data&aseide physical address for e)ery ro on e)ery ta&le+ Ance
assigned 'hen the ro is first inserted into the data&ase*( it ne)er changes until the ro is deleted or
the ta&le is dropped+The /A>ID consists of the folloing three components( the com&ination of hich uni6uely
identifies the physical storage location of the ro+ Aracle data&ase file num&er( hich contains the &loc ith the ros
Aracle &loc address( hich contains the ro The ro ithin the &loc '&ecause each &loc can hold many ros*
The /A>ID is used internally in inde;es as a 6uic means of retrie)ing ros ith a particularey )alue+ ,pplication de)elopers also use it in SJH statements as a 6uic ay to access a ro once
they no the /A>ID
73 What is =racle Bloc%? Can t+o =racle Bloc%s ha;e the same address?
Aracle LformatsL the data&ase files into a num&er of Aracle &locs hen they are first created
Kmaing it easier for the /DBS softare to manage the files and easier to read data into the
memory areas+The &loc si?e should &e a multiple of the operating system &loc si?e+ /egardless of the &loc
si?e( the entire &loc is not a)aila&le for holding data Aracle taes up some space to manage thecontents of the &loc+ This &loc header has a minimum si?e( &ut it can gro+
These Aracle &locs are the smallest unit of storage+ Increasing the Aracle &loc si?e canimpro)e performance( &ut it should &e done only hen the data&ase is first created+
Each Aracle &loc is num&ered se6uentially for each data&ase file starting at $+ To &locs can
ha)e the same &loc address if they are in different data&ase files+
74 What is dataase ri**er?
, data&ase trigger is a
8/10/2019 Lab Manual 16
78/95
Department of Computer Science and Engineering
40' create a proce!ure hich generate all the primenumbers belo the gi$en number an! count the no'ofprime numbers'
H6;S6 re9uirements"
8rocessor - AM. Athelon D "1B: ;0E
/AM - 6B M*
0ard .isk - 5! ;*
oft%are - 2racle, 8l=L
reate or replace procedure primePproc(n $N number,tot 2' number) as
i numberK
c numberK
3 numberK
*egin
i-R"K
tot-R!K
%hile(iRn)
loop
3-R"K
c-R!K
%hile(3Ri)
loop
if(mod($,3)R!) then
c-RcH"K
end ifK
Balaji Institute of Technology and Science !"
8/10/2019 Lab Manual 16
79/95
Department of Computer Science and Engineering
3-R3H"K
end loopK
if(cR) then
dbmsPoutput1putPline(i)K
tot-RtotH"K
end ifK
i-RiH"K
end loopK
endK
>
ClJprocedure created1
declare
t numberK
begin
primePproc("!,t)K
dbmsPoutput1putPline(the total prime no 1areG__t)K
endK
/ali! (est Data"
sClJset ser4eroutput on
O+(+(
sClJ>
7
6
Balaji Institute of Technology and Science !#
8/10/2019 Lab Manual 16
80/95
Department of Computer Science and Engineering
:
'he total prime no1are 5
8l>sCl procedure successfully completed1
/i$a-/ice
70 Name t+o utilities that =racle pro;ides# +hich are use $or ac%up and reco;ery,long ith the /DBS softare( Aracle pro)ides to utilities that you can use to &ac up and
restore the data&ase+ These utilities are@portandmport+
The@portutilitydumps the definitions and data for the specified part of the data&ase to anoperating system &inary file+ The mport utility reads the file produced &y an e;port( recreates the
definitions of o&jects( and inserts the data
If E;port and Import are used as a means of &acing up and reco)ering the data&ase( all the
changes made to the data&ase cannot &e reco)ered since the e;port as performed+ The &est you cando is reco)er the data&ase to the time hen the e;port as last performed+
7 What are stored-procedures? nd +hat are the ad;anta*es o$ usin* themStored procedures are data&ase o&jects that perform a user defined operation+ , stored
procedure can ha)e a set of compound SJH statements+ , stored procedure e;ecutes the SJH
commands and returns the result to the client+ Stored procedures are used to reduce netor traffic+
77 ales deri;ed $rom the @
a* ,re totally unnormalised&* ,re alays in $01
c* Can &e further denormalised
d* ay ha)e multi)alued attri&utes
'&* ,re alays in $01
78 6purious tuples may occur due to i Bad normali/ation
ii heta oins
iii >pdatin* tales $rom oina* i M ii &* ii M iii
c* i M iii d* ii M iii
'a* i M iii &ecause theta joins are joins made on eys that are not primary eys+89 B C is a set o$ attriutes he $unctional dependency is as $ollo+s
B -D B C -D C C -D B
a* is in $01
&* is in 201c* is in 301
d* is in BC01
Balaji Institute of Technology and Science "%
8/10/2019 Lab Manual 16
81/95
Department of Computer Science and Engineering
'a* is in $01 since ',C*N7 8 ,( B( C9 hence ,C is the primary ey+ Since C B is a 1Dgi)en( here neither C is a :ey nor B is a prime attri&ute( this it is not in 301+ 1urther B is not
functionally dependent on ey ,C thus it is not in 201+ Thus the gi)en 1Ds is in $01+
Balaji Institute of Technology and Science "$
8/10/2019 Lab Manual 16
82/95
Department of Computer Science and Engineering
4' create a proce!ure hich up!ates the salaries of anemployees as follos'
"1if sal"!!! then update the salry to "6!!1
1if salJR"!!! and R5!! then update the salary to 6!!1>
H6;S6 re9uirements"
8rocessor - AM. Athelon D "1B: ;0E
/AM - 6B M*
0ard .isk - 5! ;*
oft%are - 2racle, 8l=L
reate or replace procedure myproc as
ursor myPcur is select empno,sal from empK
Fno emp1empnoUtypeK
Fsal emp1salUtypeK
numberK
*egin
2pen myPcurK
-R!K
Loop
Ietch myPcur into no,salK
$f(sal"!!!) then
pdate emp set salR"6!! %here empnoRnoK
-RcH"K
+lse
$s(salJR"!!! and salR5!!) then
pdate emp set salR6!! %here empnoRnoK
Balaji Institute of Technology and Science "2
8/10/2019 Lab Manual 16
83/95
Department of Computer Science and Engineering
-RcH"K
+nd ifK
+nd ifK
+it %hen myPcurUN2'I2N.K
+nd loopK
lose myPcurK
.bmsPoutput1putPline(c__Grecords ha4e been successfully updatedG)K
+ndK
>
/ali! (est Data"
8rocedure created1
ClJeec myprocK
O+(+("
/ecords ha4e been successfully completed1
> create function %hich add t%o gi4en numbers1 (imple programs) >
reate or replace function addPfun(a number,b number) return
Number as
numberK
*egin
-RaHbK
/eturn cK
+ndK
>
Balaji Institute of Technology and Science "3
8/10/2019 Lab Manual 16
84/95
Department of Computer Science and Engineering
Iunction created1
>addPfun specification>
.eclare
/esult numberK
*egin
/esult-RaddPfun("!,!)K
.bmsPoutput1putPline(the sum of "! and ! isG__result)K
+ndK
ClJ>
'he sum of "! and ! is 7!
8l>sCl procedure successfully completed1
>create a function %hich count total no1of employees ha4ing salary less
than B!!!1>
>function body>
reate or replace function countPemp(esal number)return number as
ursor 4inPcur as elect empno,sal from empK
Fno emp1empnoUtypeK
Fsal emp1salUtypeK
numberK
*egin
2pen 4inPcurK
-R!K
loop
Balaji Institute of Technology and Science "4
8/10/2019 Lab Manual 16
85/95
Department of Computer Science and Engineering
fetch 4inPcur into no,salK
if(salesal) then
c-RcH"K
end ifK
eit %hen 4inPcurUnotfoundK
end loopK
close 4inPcurK
return cK
endK
>
Iunction created1
>function specification>
.eclare
Ne numberK
Fsal numberK
*egin
Ne-RcountPemp(sal)K
.bmsPoutput1putPline(sal)K
.bmaPoutput1putPline(there are __ne__KemployeesG)K
+ndK
>
O+(+(
'here are < employees1
/i$a-/ice"
Balaji Institute of Technology and Science "5
8/10/2019 Lab Manual 16
86/95
Department of Computer Science and Engineering
81 n mappin* o$ @
&* entity in D1D is con)erted to attri&utes of an entity in E/D
c* relations in E/D has $ to $ correspondence to processes in D1Dd* relationships in E/D has $ to $ correspondence to flos in D1D
'a* entities in E/D should correspond to an e;isting entityGstore in D1D
82 dominant entity is the entity
a* on the 0 side in a $ = 0 relationship
&* on the $ side in a $ = 0 relationshipc* on either side in a $ = $ relationship
d* nothing to do ith $ = $ or $ = 0 relationship
'&* on the $ side in a $ = 0 relationship
83 6elect EN=6=@< From C>6!A6 Where 6=@< >nion 6elect E@6E# C>6=@< From C>6!A6 Where 6=@E/E clause can &e
used ith DEHETE and not ith T/0C,TE+
10 What command is used to create a tale y copyin* the structure o$ another tale?
Answer :
C/E,TE T,BHE ++ ,S SEHECT command
Explanation :To copy only the structure( the >E/E clause of the SEHECT command should contain a
1,HSE statement as in the folloing+
C/E,TE T,BHE 0E>T,BHE ,S SEHECT 1/A E-ISTI0T,BHE >E/E $72If the >E/E condition is true( then all the ros or ros satisfying the condition ill &e
copied to the ne ta&le+
1 What +ill e the output o$ the $ollo+in* .uery?SELECT REPLACE(TRANSLATE(LTRIM(RTRIM('!! ATHEN !!','!'), '!'), 'AN',
'**'),'*','TROUBLE') FROM DUAL;
T/ABHETET/ABHE
17 What +ill e the output o$ the $ollo+in* .uery?6@A@C !@C=!@(
8/10/2019 Lab Manual 16
91/95
Department of Computer Science and Engineering
25 What is the use o$ !@6C in 6A?
Answer :
DESC has to purposes+ It is used to descri&e a schema as ell as to retrie)e ros from ta&lein descending order+
Explanation :
The 6uery SEHECT 1/A E< A/DE/ B. E0,E DESC ill display the output sorted
on E0,E in descending order+
20 What is the use o$ C6C!@ C=N6hen this clause is used ith the D/A< command( a parent ta&le can &e dropped e)en hen achild ta&le e;ists+
2 Which $unction is used to $ind the lar*est inte*er less than or e.ual to a speci$ic;alue?1HAA/
27 What is the output o$ the $ollo+in* .uery?6@A@C NC(1234507#-2) FA
$2%%
Balaji Institute of Technology and Science #$
8/10/2019 Lab Manual 16
92/95
Department of Computer Science and Engineering
%E*E%E)CES"
2'' rman, oracle =L programming,'M0#!!!
Loney, oracle
8/10/2019 Lab Manual 16
93/95
Department of Computer Science and Engineering
,+%+ )#)#J Engineering College
$brahimpatnam, / / .istrict 9 6!" 6!B (A1 81)
Assignment > /ecord No # PPPPP
.epartment of PPPPPPPPPPPPPPPPPPPPPPPP
)ame"
8/10/2019 Lab Manual 16
94/95
Department of Computer Science and Engineering
In!e7 age
S' )o' Date rogram ; E7perimentage
)o'
Sign ;
%emar8s
Balaji Institute of Technology and Science #4
#nne7ure - 1
#nne7ure - =
8/10/2019 Lab Manual 16
95/95
Department of Computer Science and Engineering
,+%+ )#)#J Engineering College
$brahimpatnam, / / .istrict 9 6!" 6!B (A1 81)
2Sponsore! by" ,uru )ana8 E!ucational Society: Hy!eraba! 2#' '3
.epartment of PPPPPPPPPPPPPPPPPPPPPPPP
(his is to certify that
)ame"