You are on page 1of 95

Department

Of
Computer Science & Engineering
Data Base Management Systems Lab Manual
BALAJI INSTITUTE OF TECHNOLOGY AND
SCIENCE
Department of computer science & engineering
In-charge HOD rincipal
repare! by" #ppro$e! &
%e$ie&e! by"
Issue! by" &'e'f Date"
Department of Computer Science and Engineering
BALAJI 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
Department of Computer Science and Engineering
I)DE-
S' )o Contents age' no
" Lab 2b3ecti4e
5
$ntroduction About Lab
6
7
)tandard 2perating 8rocedure 9
)28
:
7 ;uidelines to )tudents
<
5
.escription about )=L, 8L>)=L
statements and .?1
@
6
List of Lab +Aercises
51" )yllabus 8rograms (&N'()
51 Additional 8rograms
"!
B *ackground 'heory
"6
: )olutions for 8rograms
"
< 8L#)Cl 8rograms
6"
@ Additional Vi4a =uestion
<@
"! /eferences
@6
Balaji Institute of Technology and Science 3
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
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: ;0
E
/AM - 6B M*
0ard .isk - 5! ;*
Mouse - 2ptical Mouse
Net%ork $nterface card - 8resent
Soft&are
All systems are configured in D+#L BOO( mode i1e1, )tudents can boot
from Windo%s F8 or LinuA as per their lab reCuirement1 'his is 4ery useful
for students because they are familiar %ith different 2perating )ystems so
that they can eAecute 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 from

nd
year on%ards1
Balaji Institute of Technology and Science 5
Department of Computer Science and Engineering
M#SM 2Macro #ssembler3 is installed in all the systems
)tudents can eAecute their assembly language programs using MA)M1
MA)M is 4ery useful students because %hen they eAecute their
programs they can see contents of rocessor %egisters and ho%
each instruction is being eAecuted 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
Soft&ares installe! " ,, ,HH, &.?"16, MA)M, 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
Department of Computer Science and Engineering
S(#)D#%D OE%#(I), %OCED+%E 5 SO
a) +Aplanation on todayGs eAperiment by the concerned faculty using 208>88'
co4ering the follo%ing aspects- 6 mins1
") Name of the eAperiment>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 eAecution of the program
"!! mins1
6riting of the e7periment in the Obser$ation Boo8 -
'he students %ill %rite the todayGs eAperiment in the 2bser4ation book as
per the follo%ing format-
a) Name of the eAperiment>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>eAecution
i) )ignature of the Iaculty
Balaji Institute of Technology and Science !
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 eAercises %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 the
lab 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 "
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#Japplication
de4elopment#JsCl1
)1 You %ill be asked for user name, pass %ord and host string
You 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 from
7 empK
%here and 7 are the line numbers and rest is the command >programLL
to eAecute abo4e program>command you ha4e to press M>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 buffer
contents)1 *y gi4ing MedG at sCl prompt1(this is %hat $ mentioned as a second
method to type>enter the program)1
in the sCl editor you can do all the formatting>editing>file operations directly by
selecting menu options pro4ided by it1
'o eAecute the program %hich sa4edK do the follo%ing
)=LJ N programname1sCl
2r
)=LJ /un programname1sCl
'hen press MOG key and enter1
'his ho% %e can %rite, edit and eAecute the sCl command and programs1
Al%ays you ha4e to sa4e your programs in your o%n logins1
Balaji Institute of Technology and Science #
Department of Computer Science and Engineering
List of Lab E7ercises
Syllabus rograms 2.)(+3
S' )o )ame of the program
4 Database Schema for a customer-sale scenario
,ustomer(Cust i! " integer: custPname- string)
$tem(item<i!" integer: itemPname- string, price- integer)
)ale(bill<no" integer: billPdata- date, cust<i!" integer:
item<i!" integer, CtyPsold- integer)
Ior the abo4e schema, perform the follo%ingQ
a) ,reate the tables %ith the appropriate integrity constraints
b) $nsert around "! records in each of the tables
c) List all the bills for the current date %ith the customer names
and item numbers
d) List the total *ill details %ith the Cuantity sold, price of the
item and the final amount
e) List the details of the customer %ho ha4e bought a product
%hich has a priceJ!!
f) ;i4e a count of ho% many products ha4e been bought by
each customer
g) ;i4e a list of products bought by a customer ha4ing
custPid as 6
h) List the item details %hich are sold as of today
i) ,reate a 4ie% %hich lists out the billPno, billPdate, custPid,
itemPid, price, CtyPsold, amount
,reate a 4ie% %hich lists the daily sales date %ise for the last
one %eek
1 Database Schema for a Stu!ent Library scenario
)tudent(Stu!<no " integer: )tudPname- string)
Membership(Mem<no" integer, Stu!<no" integer)
*ook(boo8<no" integer, bookPname-string, author- string)
$ssPrec2iss<no"integer, issPdate- date, Mem<no" integer,
boo8<no" integer)
Ior the abo4e schema, perform the follo%ingQ
Balaji Institute of Technology and Science $%
Department of Computer Science and Engineering
a) ,reate the tables %ith the appropriate integrity constraints
b) $nsert around "! records in each of the tables
c) List all the student names %ith their membership numbers
d) List all the issues for the current date %ith student and
*ook names
e) List the details of students %ho borro%ed book %hose
author is ,&.A'+
f) ;i4e a count of ho% many books ha4e been bought by
each student
g) ;i4e a list of books taken by student %ith studPno as 6
h) List the book details %hich are issued as of today
i) ,reate a 4ie% %hich lists out the issPno, iss Pdate,
studPname, book name
3) ,reate a 4ie% %hich lists the daily issues#date %ise for the
last one %eek
= Database Schema for a Employee-pay scenario
employee(emp<i! " integer , empPname- string)
department(!ept<i!" integer, deptPname-string)
paydetails(emp<i! " integer, !ept<i!" integer, basic- integer,
deductions- integer, additions- integer, .2&- date)
payroll2emp<i! " integer, payPdate- date)
Ior the abo4e schema, perform the follo%ingQ
a) ,reate the tables %ith the appropriate integrity constraints
b) $nsert around "! records in each of the tables
c) List the employee details department %ise
d) List all the employee names %ho 3oined after particular
date
e) List the details of employees %hose basic salary is
bet%een "!,!!! and !,!!!
f) ;i4e a count of ho% many employees are %orking in each
department
g) ;i4e a names of the employees %hose netsalaryJ"!,!!!
h) List the details for an employeePidR6
i) ,reate a 4ie% %hich lists out the empPname, department,
basic, dedeuctions, netsalary
3) ,reate a 4ie% %hich lists the empPname and his netsalary
> Database Schema for a /i!eo Library scenario
,ustomer(custPno- integer,custPname- string)
Membership(Mem<no" integer, cust<no" integer)
,assette(cass<no"integer, cassPname-string, Language-
)tring)
$ssPrec2iss<no" integer, issPdate- date, mem<no" integer,
Balaji Institute of Technology and Science $$
Department of Computer Science and Engineering
cass<no" integer)
Ior the abo4e schema, perform the follo%ingQ
a) ,reate the tables %ith the appropriate integrity constraints
b) $nsert around "! records in each of the tables
c) List all the customer names %ith their membership
numbers
d) List all the issues for the current date %ith the customer
names and cassette names
e) List the details of the customer %ho has borro%ed the
cassette %hose title is S 'he LegendT
f) ;i4e a count of ho% many cassettes ha4e been borro%ed
by each customer
g) ;i4e a list of book %hich has been taken by the student
%ith memPno as 6
h) List the cassettes issues for today
i) ,reate a 4ie% %hich lists outs the issPno, issPdate,
custPname, cassPname
3) ,reate a 4ie% %hich lists issues#date %ise for the last one
%eek
? Database Schema for a stu!ent-Lab scenario
)tudent(stu!<no" integer, studPname- string, class" string)
,lass(class" string: !escrip" string)
Lab(mach<no" integer, LabPno- integer, description- )tring)
Allotment(Stu!<no" Integer: mach<no" integer: !ayof
&ee8" string3
Ior the abo4e schema, perform the follo%ingQ
a) ,reate the tables %ith the appropriate integrity constraints
b) $nsert around "! records in each of the tables
c) List all the machine allotments %ith the student names,
lab and machine numbers
d) List the total number of lab allotments day %ise
e) ;i4e a count of ho% many machines ha4e been allocated
to the M,)$'G class
f) ;i4e a machine allotment etails of the studPno 6 %ith his
personal and class details
g) ,ount for ho% many machines ha4e been allocatedin
Lab<no 4 for the day of the %eek as SMondayT
h) 0o% many students class %ise ha4e allocated machines in
the labs
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'hursdayT1
@ Write a program to find largest number from the gi4en three
numbers1
Balaji Institute of Technology and Science $2
Department of Computer Science and Engineering
A )imple programs using loop, %hile and for iterati4e control
statement1
B Write a program to check %hether the gi4en number is
Armstrong or not
0 Write a program to generate all prime numbers belo% "!!1
4C Write a program to demonstrate the ;2'2 statement1
44 Write a program to demonstrate Utype and Uro%type attributes
41 Write a program to demonstrate predefined eAceptions
4= Write a program to demonstrate user defined eAceptions
4> ,reate a cursor, %hich displays all employee numbers and
names from the +M8 table1
4? ,reate a cursor, %hich update the salaries of all employees as
per the gi4en data1
4@ ,reate a cursor, %hich displays names of employees ha4ing
salary J 6!!!!1
4A ,reate a procedure to find re4erse of a gi4en number
4B ,reate a procedure to update the salaries of all employees as
per the gi4en data
40 ,reate a procedure to demonstrate $N, 2(' and $N2('
parameters
1C ,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%>statement1
1> ,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 salariesL1
#!!itional rograms
S' )o )ame of the rogram
4 ,reate a form using Iorms Bi to display +mployee table
data1
1 ,reate a Master>details relationship form %hich
perform Add Ne%, )earch, .elete, )a4e and (pdate on
the records
= ;enerate a report to calculate employeeGs salaries
Balaji Institute of Technology and Science $3
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
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
<!U of the /.*M)systems sold %orld%ide1
'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 <i and @i also under stand )=L&1
2racle corp has also incorporated a full#fledged 3a4a 4irtual machine into its
database engine1since both eAecutable share the same memory space the &VM
can communicate With the database engine %ith ease and has direct access to
oracle tables and their data1
)=L is structure Cuery language1)=L contains different data types those are
"1 char(siEe)
1 4archar(siEe)
71 date
51 number(p,s)
61 long
B1 ra%>long ra%
Different types of comman!s in SDL"
A)1 DDL comman!s" - 'o create a database ob3ects
*)1 DML comman!s" - 'o manipulate data of a database ob3ects
,)1 DDL comman!" - 'o retrie4e the data from a database1
.)1 DCL;D(L comman!s" - 'o control the data of a databaseL
DDL comman!s"
4' (he Create (able Comman!" - it defines each column of the table uniCuely1
+ach column has minimum of three attributes, a name , data type and siEe1
Synta7"
Create table Vtable nameJ (Vcol"J VdatatypeJ(VsiEeJ),VcolJ
VdatatypeJVsiEeJ))K
E7"
create table emp(empno number(5) primary key, ename char("!))K
1' Mo!ifying the structure of tables'
a)add ne% columns
Synta7"
Balaji Institute of Technology and Science $5
Department of Computer Science and Engineering
#lter table VtablenameJ add(Vne% colJVdatatype(siEe),Vne%
colJdatatype(siEe))K
E7"
alter table emp add(sal number(:,))K
=' Dropping a column from a table'
Synta7"
Alter table VtablenameJ drop column VcolJK
E7"
alter table emp drop column salK
>' Mo!ifying e7isting columns'
Synta7"
Alter table VtablenameJ modify(VcolJVne%datatypeJ(Vne%siEeJ))K
E7"
alter table emp modify(ename 4archar("6))K
?' %enaming the tables
Synta7"
%ename VoldtableJ to Vne% tableJK
E7"
rename emp to emp"K
@' truncating the tables'
Synta7"
(runcate table VtablenameJK
E7"
trunc table emp"K
A' Destroying tables'
Synta7"
Drop table VtablenameJK
E7"
drop table empK
Balaji Institute of Technology and Science $
Department of Computer Science and Engineering
DML comman!s"
B' Inserting Data into (ables" - once a table is created the most natural thing
to do is load this table %ith data to be manipulated later1
Synta7"
insert into VtablenameJ (Vcol"J,VcolJ) 4alues(VeApJ,VeApJ)K
0' Delete operations'
a3 remo4e all ro%s
Synta7"
delete from VtablenameJK
b3 remo4al of a specified ro%>s
Synta7"
delete from VtablenameJ %here VconditionJK
4C' +p!ating the contents of a table'
a3 updating all ro%s
Synta7"
(pdate VtablenameJ set VcolJRVeApJ,VcolJRVeApJK
b3 updating seleted records1
)yntaA-
(pdate VtablenameJ set VcolJRVeApJ,VcolJRVeApJ
%here VconditionJK
44' (ypes of !ata constrains'
a3 not null constraint at column le4el1
Synta7"
VcolJVdatatypeJ(siEe)not null
b3 uniCue constraint
Synta7"
(niCue constraint at column le4el1
VcolJVdatatypeJ(siEe)uniCueK
c3 uniCue constraint at table le4el-
Synta7"
,reate table tablename(colRformat,colRformat,uniCue(Vcol"J,VcolJ)K
!3 primary key constraint at column le4el
Synta7"
VcolJVdatatypeJ(siEe)primary keyK
Balaji Institute of Technology and Science $!
Department of Computer Science and Engineering
e3 primary key constraint at table le4el1
Synta7"
,reate table tablename(colRformat,colRformat
primary key(col"J,VcolJ)K
f3 foreign key constraint at column le4el1
Synta7"
VcolJVdatatypeJ(siEeJ) references VtablenameJWVcolJXK
g3 foreign key constraint at table le4el
Synta7"
foreign key(VcolJW,VcolJX)references VtablenameJW(VcolJ,VcolJ)
h3 check constraint
check constraint constraint at column le4el1
Synta7" VcolJVdatatypeJ(siEe) check(Vlogical eApressionJ)
i3 check constraint constraint at table le4el1
Synta7" check(Vlogical eApressionJ)
Balaji Institute of Technology and Science $"
Department of Computer Science and Engineering
DDL Comman!s"
41' /ie&ing !ata in the tables- # once data has been inserted into a table, the
neAt most logical operation %ould be to 4ie% %hat has been inserted1
a3 all ro%s and all columns
Synta7"
)elect VcolJ to Vcol nJ from tablenameK
)elect Y from tablenameK
4=' *iltering table !ata- # %hile 4ie%ing data from a table, it is rare that all the
data from table %ill be reCuired each time1 0ence, sCl must gi4e us a method of
filtering out data that is not reCuired data1
a3 )elected columns and all ro%s-
Synta7"
select Vcol"J,VcolJ from VtablenameJK
b3 selected ro%s and all columns-
Synta7"
select Y from VtablenameJ %here VconditionJK
c3 selected columns and selected ro%s
Synta7"
select Vcol"J,VcolJ from VtablenameJ %hereVconditionJK
4>' Sorting !ata in a table'
Synta7"
)elect Y from VtablenameJ order by Vcol"J,VcolJ VWsortorderXJK
DCL comman!s"
2racle pro4ides eAtensi4e 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 as
tables,4ie%s and seCuences and so on1
Synta7"
;/AN' Vob3ect pri4ilegesJ
2N Vob3ectnameJ
'2VusernameJ
Balaji Institute of Technology and Science $#
Department of Computer Science and Engineering
WW$'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?+Vob3ect pri4ilegeJ
2N
I/2MVuser nameJK
Balaji Institute of Technology and Science 2%
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<i!" integer, itemPname- string, price- integer)
)ale(bill<no" integer, billPdata- date, cust<i!" integer: item<i!" integer,
CtyPsold- integer)
Ior the abo4e schema, perform the follo%ingQ
a) ,reate the tables %ith the appropriate integrity constraints
b) $nsert around "! records in each of the tables
c) List all the bills for the current date %ith the customer names and item
numbers
d) List the total *ill details %ith the Cuantity sold, price of the item and the
final amount
e) List the details of the customer %ho ha4e bought a product %hich has a
priceJ!!
f) ;i4e a count of ho% many products ha4e been bought by each customer
g) ;i4e a list of products bought by a customer ha4ing custPid as 6
h) List the item details %hich are sold as of today
i) ,reate a 4ie% %hich lists out the billPno, billPdate, custPid, itemPid, price,
CtyPsold, amount
3) ,reate a 4ie% %hich lists the daily sales date %ise for the last one %eek
Balaji Institute of Technology and Science 2$
Department of Computer Science and Engineering
#im- ,reate the tables %ith the appropriate integrity constraints and $nsert
around "! records in each of the tables
H6;S6 re9uirements"
8rocessor - AM. Athelon D "1B: ;0
E
/AM - 6B M*
0ard .isk - 5! ;*
)oft%are - 2/A,L+

)=LJ create table customer" (custPid number(6) primary key, custPname
4archar("6))K
Output" 'able created1
)=LJ desc customer"K
Output"
Name NullZ 'ype
######################################### ######## ################
,()'P$. N2' N(LL N(M*+/(6)
,()'PNAM+ VA/,0A/("6)
/ali! (est Data
b3 )=LJ insert into customer" 4alues([custid,\[custname\)K
)=LJ select Y 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
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
,ustPid N2' N(LL N(M*+/(5)
$temPname VA/,0A/("6)
8/$,+ N(M*+/(B,)
Balaji Institute of Technology and Science 22
Department of Computer Science and Engineering
)=LJinsert into item 4alues([itemPid,G[itemPnameG,[price)K


)=LJ select Y from itemK
Output"
$'+MP$. $'+MPNAM+ 8/$,+
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL11
775 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, custPid
number(6) references customer(custPid), itemPid number(5) references
item(itemPid),CtyPsold number(5))K
Out put- 'able ,reated1
)=LJdsec sale
Output"
Name NullZ 'ype
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL11
*$LLPN2 N2' N(LL N(M*+/(5)
*$LLP.A'+ .A'+
,()'P$. N(M*+/(6)
$'+MP$. N(M*+/(5)
='YP)2L. N(M*+/(5)
)=LJinsert into )ale 4alues([billPno, G[billPdateG,
[custPid, [itemPid, [CtyPsold)K
)=LJselect Y from saleK
Output"
*$LLPN2 *$LLP.A'+ ,()'P$. $'+MP$. ='YP)2L.
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL111
"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 item
numbers
)=LJ select c1custname, i1itemid, s1billno from customer c, item $, sale s
%here c1custidRs1custid and
Balaji Institute of Technology and Science 23
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,(i1priceYs1Cty) total from item $, sale s %here
i1itemidRs1itemidK
8/$,+ ='Y '2'AL
####### ##### ########
"! 5!
! 7 B!
6 "!
"! " "!
76! 5 "5!!
e3 List the details of the customer %ho ha4e bought a product %hich has a
priceJ!!
)=LJ select c1custid, c1custname from customer c, sale s, item i %here
i1priceJ!! and
c1custidRs1custid 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
,()'$. ,2(N'($'+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
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
i1itemidRs1itemid
and 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 Y from custK
*$LLN2 *$LL.A'+ ,()'$. $'+M$. 8/$,+ ='Y
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
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
E3 ,reate a 4ie% %hich lists the daily sales date %ise for the last one
%eek
/i$a-/oce"
="1 What is )=LZ
Ans- )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
Department of Computer Science and Engineering
3. What is DBMS?
$t is a collection of programs that enables user to create and maintain a
database1 $n other %ords it is general#purpose soft%are that pro4ides the users
%ith the processes of defining, constructing and manipulating the database for
4arious 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
Department of Computer Science and Engineering
1' Database Schema for a Stu!ent Library scenario
)tudent(Stu!<no " integer: )tudPname- string)
Membership(Mem<no" integer, Stu!<no" integer)
*ook(boo8<no" integer, bookPname-string, author- string)
$ssPrec2iss<no"integer, issPdate- date, Mem<no" integer, boo8<no" integer)
*or the abo$e schema: perform the follo&ingF
a3 ,reate the tables %ith the appropriate integrity constraints
b3 $nsert around "! records in each of the tables
c3 List all the student names %ith their membership numbers
!3 List all the issues for the current date %ith student and *ook names
e3 List the details of students %ho borro%ed book %hose author is ,&.A'+
f3 ;i4e a count of ho% many books ha4e been bought by each student
g3 ;i4e a list of books taken by student %ith studPno as 6
h3 List the book details %hich are issued as of today
i3 ,reate a 4ie% %hich lists out the issPno, iss Pdate, studPname, book name
E3 ,reate a 4ie% %hich lists the daily issues#date %ise for the last one %eek
Balaji Institute of Technology and Science 2!
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: ;0
E
/AM - 6B M*
0ard .isk - 5! ;*
)oft%are - 2racle
)=LJcreate table student(studPno number(6) primary key,studPname
4archar("6))K
)=LJdesc studentK
Name NullZ 'ype
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL11
)'(.PN2 N2' N(LL N(M*+/(6)
)'(.PNAM+ VA/,A0/("6)
/ali! (est Data"
)=LJinsert into student 4alues([studPno,G[studPnameG)K
)=LJselect Y from studentK
)'(.PN2 )'(.PNAM+
11111111111111111111111111111111111111111111111111111111111111111111
6!< 0A/$)0
6"7 *ALA&$
6"< /A?+)0
65 8AVAN
675 &2Y,+
)=LJcreate table membership(memPno number(6) primary key,studPno
number(6) references student(stud)no))K
)=LJdsec membershipK
Name NullZ 'ype
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL1
M+MPN2 N2' N(LL N(M*+/(6)
)'(.PN2 N(M*+/(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"
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"!)
Y
Errors Obser$e!"
+//2/ at line "-
2/A#!@"-integrity constraint(0A/$)01)Y)P,!!:5)4iolated#primary key not
found
)=LJselect Y from membershipK
M+MPN2 )'(.PN2
LLLLLLLLLLLLLLLLLLLLLLLLLLL11
655! 6"7
655" 6!<
655 6"<
6557 675
6555 65
)=LJcreate table book(bookPno number(6) primary key,bookPname
4archar(!),author 4archar())K
)=LJdesc bookK
Name NullZ 'ype
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL11
*22?PN2 N2' N(LL N(M*+/(6)
*22?PNAM+ VA/,0A/(!)
A('02/ VA/,0A/(!)
)=LJinsert into book 4alues([bookPno,G[bookPnameG,G[authorG)K
)=LJselect Y from bookK
*22?PN2 *22?PNAM+ A('02/
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL11
@"7 .*M) /ama ?rishna
75 &AVA /obett %ilkins
567 Iearless tales Alfred
<:7 my ambition 0arish
:<" 0arry 8otter &? /o%ling
)=LJcreate table lssPrec(issPno number primary key,issPdate date,memPno
number(6) references membership(memPno),bookPno number(6) references
book(bookPno))K
)=LJdesc issPrecK
Name NullZ 'ype
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
Balaji Institute of Technology and Science 2#
Department of Computer Science and Engineering
$))PN2 N2' N(LL N(M*+/
$))P.A'+ .A'+
M+MPN2 N(M*+/(6)
*22?PN2 N(M*+/(6)
)=LJselect Y from issPrecK
$))PN2 $))P.A'+ M+MPN2 *22?PN2
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
57 !6#&AN#!B 6557 567
<" <#.+,#!6 655" <:7
!<#.+,#!6 655! :<"
67 !:#&AN#!B 655 @"7
76 !B#&AN#!B 6555 75
c3 List all the student names %ith their membership numbers
)=LJ select s1studname, m1memno from student s, membership m %here
m1studnoRs1studnoK
)'(.NAM+ M+MN2
#####################
abhi3eet "!!"
arun "!!
ar4ind "!!7
ashish "!!5
ash%in "!!6
!3 List all the issues for the current date %ith student and *ook names
)=LJ select i1issno, s1studname, b1bookname from issPrec $, membership m,
student s, book b
%here i1memnoRm1memno and m1studnoRs1studno and
i1issdateRtoPchar(sysdate)K
$))N2 )'(.NAM+ *22?NAM+
####### ############ ###############
"7 ar4ind 8[)
e3 List the details of students %ho borro%ed book %hose author is ,&.A'+
)=LJ select Y from student %here studno in(select studno from membership
%here memno in
(select memno from issPrec %here bookno in(select bookno from book %here
authorRG,&.A'+G)))K
)'(.N2 )'(.NAM+
Balaji Institute of Technology and Science 3%
Department of Computer Science and Engineering
########## #############
6!6 ash%in
f3 ;i4e a count of ho% many books ha4e been bought by each student
)=LJ select s1studno, count(i1bookno) from student s1membership m, book b,
issPrec $ %here s1studnoRm1studno and b1booknoRi1bookno group by s1studnoK
)'(.N2 ,2(N'($1*22?N2)
########## #######################
6!" 6
6! 6
6!7 6
6!5 6
6!6 6
g3 ;i4e a list of books taken by student %ith studPno as 6
)=LJ select bookname from book %here bookno in (select bookno from issPrec
%here
memno in(select memno from membership %here
7 studno in(select studno from student %here studnoR6)))K
*22?NAM+
#############
N'
h3 List the book details %hich are issued as of today
)=LJ delete from book %here bookno in(select bookno from issPrec %here
issdateRtoPchar(sysdate))K
delete from book %here bookno in (select bookno from issPrec %here
issdateRtoPchar(sysdate))
Errors Obser$e!"
+//2/ at line "-
2/A#!@- integrity constraint (),2''1)Y)P,!!<5!) 4iolated 9 child record
found
i3 ,reate a 4ie% %hich lists out the issPno, iss Pdate, studPname, book name
E3 ,reate a 4ie% %hich lists the daily issues#date %ise for the last one %eek
Balaji Institute of Technology and Science 3$
Department of Computer Science and Engineering
/i$a-/ice"
%. Describe the three le!els of data abstraction?
'he are three le4els of abstraction-
$hysical le!el& 'he lo%est le4el of abstraction describes ho% data are stored1
'ogical le!el& 'he neAt higher le4el of abstraction, describes %hat data are
stored in database and %hat relationship among those data1
(ie) le!el& 'he highest le4el of abstraction describes only part of entire
database1
2. Define the *integrity rules*
'here are t%o $ntegrity rules1
+ntity ,ntegrity& )tates that S8rimary key cannot ha4e N(LL 4alueT
-eferential ,ntegrity& )tates that SIoreign ?ey can be either a N(LL
4alue or should be 8rimary ?ey 4alue of other relation1
3. What is e.tension and intension?
+.tension #
$t is the number of tuples present in a table at any instance1 'his is
time dependent1
,ntension #
$t is a constant 4alue that gi4es the name, structure of table and the
constraints laid on it1
4. What is System -? What are its t)o ma/or subsystems?
)ystem / %as designed and de4eloped o4er a period of "@:5#:@ at $*M
)an &ose /esearch ,enter1 $t is a prototype and its purpose %as to demonstrate
that it is possible to build a /elational )ystem that can be used in a real life
en4ironment to sol4e real life problems, %ith performance at least comparable to
that of eAisting system1
$ts t%o subsystems are
/esearch )torage
)ystem /elational .ata )ystem1
5. 0o) is the data structure of System - different from the relational structure?
(nlike /elational systems in )ystem /
.omains are not supported
+nforcement of candidate key uniCueness is optional
+nforcement of entity integrity is optional
/eferential integrity is not enforced
". What is Data ,ndependence?
.ata independence means that Sthe application is independent of the
storage structure and access strategy of dataT1 $n other %ords, 'he ability to
Balaji Institute of Technology and Science 32
Department of Computer Science and Engineering
modify the schema definition in one le4el should not affect the schema definition
in the neAt higher le4el1
'%o types of .ata $ndependence-
8hysical .ata $ndependence- Modification in physical le4el should not
affect the logical le4el1
Logical .ata $ndependence- Modification in logical le4el should affect
the 4ie% le4el1
123+& 'ogical Data ,ndependence is more difficult to achie!e
4. What is a !ie)? 0o) it is related to data independence?
A 4ie% may be thought of as a 4irtual table, that is, a table that does not
really eAist in its o%n right but is instead deri4ed from one or more underlying
base table1 $n other %ords, there is no stored file that direct represents the 4ie%
instead a definition of 4ie% is stored in data dictionary1
;ro%th and restructuring of base tables is not reflected in 4ie%s1 'hus the
4ie% can insulate users from the effects of restructuring and gro%th in the
database1 0ence accounts for logical data independence1
=' Database Schema for a Employee-pay scenario
employee(emp<i! " integer , empPname- string)
department(!ept<i!" integer, deptPname-string)
paydetails(emp<i! " integer, !ept<i!" integer, basic- integer, deductions-
integer, additions- integer, .2&- date)
payroll2emp<i! " integer, payPdate- date)
*or the abo$e schema: perform the follo&ingF
a) ,reate the tables %ith the appropriate integrity constraints
b) $nsert around "! records in each of the tables
c) List the employee details department %ise
d) List all the employee names %ho 3oined after particular date
e) List the details of employees %hose basic salary is bet%een "!,!!! and
!,!!!
f) ;i4e a count of ho% many employees are %orking in each department
g) ;i4e a names of the employees %hose netsalaryJ"!,!!!
h) List the details for an employeePidR6
i) ,reate a 4ie% %hich lists out the empPname, department, basic,
dedeuctions, netsalary
3) ,reate a 4ie% %hich lists the empPname and his netsalary
Balaji Institute of Technology and Science 33
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: ;0
E
/AM - 6B M*
0ard .isk - 5! ;*
)oft%are - 2racle

,reate table employee(empPid number(6) primary key,empPname
4archar(6))K
)=LJdesc employeeK
Name NullZ 'ype
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL11
+M8P$. N2' N(LL N(M*+/(6)
+M8PNAM+ VA/,0A/(6)
/ali! (est Data"
)=LJinsert into employee 4alues([empPid,G[empPnameG)K
)=LJselect Y from employeeK
+M8P$. +M8PNAM+
LLLLLLLLLLLLLLLLLLLLLL1
"! /obert
" ,oulthard
7! Iernando Alonso
7@ ?artikeyan
<: ?immi
)=LJcreate table department(deptPid number(6) primary key,deptPname
4archar(!))K
)=LJdesc departmentK
Name NullZ 'ype
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL11
.+8'P$. N2' N(LL N(M*+/(6)
.+8'PNAM+ VA/,0A/(!)
)=LJinsert into department 4alues([deptPid,G[deptPnameG)K
)=LJselect Y from departmentK
.+8'P$. .+8'PNAM+
Balaji Institute of Technology and Science 34
Department of Computer Science and Engineering
LLLLLLLLLLLLLLLLLLLLLLLLLLLLL11
"!! sales
"!" accounts
"! administration
"!7 production
"!5 super4isor
)=LJcreate table paydetails(empPid number(6) references
employee(empPid),deptPid number(6) reerences department(deptPid),basic
number(:,),deductions number(6,),additions number(6,),do3 date)K
)=LJdesc paydetailsK
Name NullZ 'ype
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL11
+M8P$. N(M*+/(6)
.+8'P$. N(M*+/(6)
*A)$, N(M*+/(:,)
.+.(,'$2N) N(M*+/(6,)
A..$'$2N) N(M*+/(6,)
.2& .A'+
Different Data Sets"
)=LJinsert into paydeatils 4alues([empPid,[deptPid,
[basic,[deductions,[additions,[do3)K
)=LJselect Y from paydeatilsK
+M8P$. .+8'P$. *A)$, .+.(,'$2N) A..$'$2N) .2&
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL11
"! "!" 6!71" 571!@ :"17 !<#&AN#@7
" "!! "!6!!1@ 71@< 5!1@ !"#&AN#!B
7! "! B6!!16 7!165 "6 !B#&(L#@:
7@ "!7 @:!!156 71:< B61!@ !<#A(;#!7
<: "!5 "6!!! @:1BB "651< 5#)+8#!5
)=LJcreate table payroll(empPid number(6)references
employee(empPid),payPdate date)K
)=LJdesc payrollK
Name NullZ 'ype
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL11
+M8P$. N(M*+/(6)
8AYP.A'+ .A'+
)=LJinsert into payroll 4alues([empPid,G[dateG)K
Balaji Institute of Technology and Science 35
Department of Computer Science and Engineering
)=LJselect Y from payrollK
+M8P$. 8AYP.A'+
LLLLLLLLLLLLLLLLLLLLLL1
"! 7"#&AN#!B
" !7#I+*#!B
7! "6#&AN#!B
7@ :#&AN#!B
<: !5#I+*#!B
c3 List the employee details department %ise
)=LJselect empid,deptid from paydetK
+M8$. .+8'$.
LLLLLLLLLL
5!" 6!!
5! !!
5!7 B!!
5!5 5!!
5!6 "!!
d) List all the employee names %ho 3oined after particular date
)=LGselect e,empname from employee e,paydet p %here e1empidRp1empid and
p1do3JRG!6#mar#!BGK
+M8NAM+
LLLLLLL
AV$NA)0
N$'$N
80AL;(N
e) List the details of employees %hose basic salary is bet%een "!,!!! and
!,!!!
sCLJ )elect empid,empname from employee %here salary bet%een "!!!! and
!!!!K
+M8$. +M8NAM+
LLLLLLLLLLL1
5! A?0$LA
5!7 aaaaaaaa
+M8$. +M8NAM+
LLLLLLLLLLL1
A?0$LA
f) ;i4e a count of ho% many employees are %orking in each department
Balaji Institute of Technology and Science 3
Department of Computer Science and Engineering
)=LJselect count(empid),deptid from paydet group by deptidK
,2(N' (+M8$.) .+8'$.
LLLLLLLLLLLLLLLLLLLLL
" !!
" 5!!
" 6!!
" B!!
" "!!
g) ;i4e a names of the employees %hose netsalaryJ"!,!!!
)=LJ select empname from employee %here empid in(select empid from paydet
%here basic#deductionJ"!!!!)K
+M8NAM+
LLLLLL
AV$NA)0
A?0$LA
0A/$)0
N$'$N
80AL;(N
h) List the details for an employeePidR6
)=LJ select Y from employee %here empidR6K
+M8$. +M8NAM+
##########################################
6 ,oulthard
i) ,reate a 4ie% %hich lists out the empPname, department, basic,
dedeuctions, netsalary
3) ,reate a 4ie% %hich lists the empPname and his netsalary
/i$a-/ice"
%3. What is Data Model?
A collection of conceptual tools for describing data, data relationships data
semantics and constraints1
Balaji Institute of Technology and Science 3!
Department of Computer Science and Engineering
%4. What is +5- model?
'his data model is based on real %orld that consists of basic ob3ects called
entities and of relationship among these ob3ects1 +ntities are described in a
database by a set of attributes1
%5. What is 2b/ect 2riented model?
'his model is based on collection of ob3ects1 An ob3ect contains 4alues
stored in instance 4ariables %ith in the ob3ect1 An ob3ect also contains bodies of
code that operate on the ob3ect1 'hese bodies of code are called methods1
2b3ects that contain same types of 4alues and the same methods are grouped
together into classes1
%". What is an +ntity?
$t is a \thing\ in the real %orld %ith an independent eAistence1
%4. What is an +ntity type?
$t is a collection (set) of entities that ha4e same attributes1
%6. What is an +ntity set?
$t is a collection of all entities of particular entity type in the database1
Balaji Institute of Technology and Science 3"
Department of Computer Science and Engineering
>' Database Schema for a /i!eo Library scenario
,ustomer(custPno- integer,custPname- string)
Membership(Mem<no" integer, cust<no" integer)
,assette(cass<no"integer, cassPname-string, Language- )tring)
$ssPrec2iss<no" integer, issPdate- date, mem<no" integer, cass<no" integer)
*or the abo$e schema: perform the follo&ingF
a) ,reate the tables %ith the appropriate integrity constraints
b) $nsert around "! records in each of the tables
c) List all the customer names %ith their membership numbers
d) List all the issues for the current date %ith the customer names and
cassette names
e) List the details of the customer %ho has borro%ed the cassette %hose title
is S 'he LegendT
f) ;i4e a count of ho% many cassettes ha4e been borro%ed by each customer
g) ;i4e a list of book %hich has been taken by the student %ith memPno as 6
h) List the cassettes issues for today
i) ,reate a 4ie% %hich lists outs the issPno, issPdate, custPname, cassPname
3) ,reate a 4ie% %hich lists issues#date %ise for the last one %eek
Balaji Institute of Technology and Science 3#
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: ;0
E
/AM - 6B M*
0ard .isk - 5! ;*
)oft%are - 2racle
)=LJcreate table customer(custPno number(6) primary key,custPname
4archar(!))K
)=LJdesc customerK
Name NullZ 'ype
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL11
,()'PN2 N2' N(LL N(M*+/(6)
,()'PNAM+ VA/,0A/(!)
/ali! (est Data"
)=LJinsert into customer 4alues([custPno,G[custPnameG)K
)=LJselect Y from customerK
,()'PN2 ,()'PNAM+
LLLLLLLLLLLLLLLLLLLLLLLL1
6! scott
6" pandey
6 4arshney
67 naidu
65 bhimbra
)=LJcreate table membership(memPno number(6) primary key,custPno
number(6) references customer(custPno))K
)=LJdsec membershipK
Name NullZ 'ype
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL111
M+MPN2 N2' N(LL N(M*+/(6)
,()'PN2 N(M*+/(6)
)=LJinsert into memship 4alues([memPno,[custPno)K
)=LJselect Y from memshipK
Balaji Institute of Technology and Science 4%
Department of Computer Science and Engineering
M+MPN2 ,()'PN2
LLLLLLLLLLLLLLLLLLL
@! 6!
@<" 6"
<@: 6
<! 67
@< 65
)=LJcreate
table cassette(cassPno number(6) primary key,
,assPname 4archar("6),language 4archar("6))K
)=LJdesc cassetteK
Name NullZ 'ype
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL11
,A))PN2 N2' N(LL N(M*+/(6)
,A))PNAM+ VA/,0A/("6)
LAN;(A;+ VA/,0A/("6)
)=LJinsert into cassette 4alues([cassPno,G[cassPnameG,G[languageG)K
)=LJselect Y from cassetteK
,A))PN2 ,A))PNAM+ LAN;(A;+
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
" tagore telugu
the lion king +nglish
7 anniyan tamil
5 indra telugu
6 lord of rings +nglish
)=LJcreate table issuPrec(issPno number(6) primary key,issPdate date,memPno
number(6)references memship(memPno),cassPno number(6) references
cassette(cassPno))K
)=LJdesc issuPrecK
Name NullZ 'ype
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL111
$))PN2 N2' N(LL N(M*+/(6)
$))P.A'+ .A'+
M+MPN2 N(M*+/(6)
,A))PN2 N(M*+/(6)
)=LJselect Y from issuPrecK
$))PN2 $))P.A'+ M+MPN2 ,A))PN2
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
Balaji Institute of Technology and Science 4$
Department of Computer Science and Engineering
!:#&AN#!B @! "
7 "!#&AN#!! @<"
B "!#&AN#!B <@: 6
7 !"#&AN#!B <! 5
75 7"#.+,#!6 @< 7
c) List all the customer names %ith their membership numbers
)=LJselect c1custname,m1memno from customer" c,membership" m %here
c1custnoRm1custnoK
,()'NAM+ M+MN2
LLLLLL11 LLLLLL11
N$?0$L 6"
V$V+? 6
)0/AVAN 6<
VAM)$ 6:
)0$VA 6B
d) List all the issues for the current date %ith the customer names and
cassette names
)=LJselect i1issno,c1custname,cc1cassettename from customer"
c,membership" m,cassette cc,issrec" $ %here i1issdateRtoPchar(sysdate)
and c1custnoRm1custno and i1cassnoRcc1cassno and i1memnoRm1memnoK
Outut"
no ro%s selected1
e) List the details of the customer %ho has borro%ed the cassette %hose title
is S 'he LegendT
f) ;i4e a count of ho% many cassettes ha4e been borro%ed by each customer
g) ;i4e a list of book %hich has been taken by the student %ith memPno as 6
h) List the cassettes issues for today
i) ,reate a 4ie% %hich lists outs the issPno, issPdate, custPname, cassPname
3) ,reate a 4ie% %hich lists issues#date %ise for the last one %eek
/i$a-/ice"
%7. What is an +.tension of entity type?
'he collections of entities of a particular entity type are grouped together
into an entity set1
28. What is Wea9 +ntity set?
Balaji Institute of Technology and Science 42
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 parent
entity, 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, L, An) is made up of the relation
name / 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!<no" integer, studPname- string, class" string)
,lass(class" string: !escrip" string)
Lab(mach<no" integer, LabPno- integer, description- )tring)
Allotment(Stu!<no" Integer: mach<no" integer: !ayof &ee8" string3
*or the abo$e schema: perform the follo&ingF
a) ,reate the tables %ith the appropriate integrity constraints
b) $nsert around "! records in each of the tables
c) List all the machine allotments %ith the student names, lab and machine
numbers
d) List the total number of lab allotments day %ise
e) ;i4e a count of ho% many machines ha4e been allocated to the M,)$'G class
Balaji Institute of Technology and Science 43
Department of Computer Science and Engineering
f) ;i4e a machine allotment etails of the studPno 6 %ith his personal and
class details
g) ,ount for ho% many machines ha4e been allocatedin Lab<no 4 for the
day of the %eek as SMondayT
h) 0o% many students class %ise ha4e allocated machines in the labs
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
Balaji Institute of Technology and Science 44
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: ;0
E
/AM - 6B M*
0ard .isk - 5! ;*
)oft%are - 2racle
)=LJcreate table stu(studPno number(6) primary key,studPnam
4archar(!),class 4archar(!))K
)=LJ desc stuK
Name nullZ 'ype
)'(.PN2 N2' N(LL N(M*+/(6)
)'(.PNAM VA/,0A/(!)
,LA)) VA/,0A/(!)
/ali! Data Sets"
)=LJ insert into stu 4alues([studPno,G[studPnamG,G[classG)K
)=LJ select Y from stuK
)'(.PN2 )'(.PNAM ,LA))
7@ L+2N ,)+
75 V$?A) ,)$'
"< MA'0+W +,+
< 0AN)+N M+,0
5 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), description
4archar(!))K
)=LJ desc labK
Balaji Institute of Technology and Science 45
Department of Computer Science and Engineering
Name null type
MA,0PN2 N2' N(LL N(M*+/(6)
LA*PN2 N(M*+/(6)
.+),/$8'$2N VA/,0A/(!)
)=LJ insert into lab 4alues([machPno,[labPno,G[descriptionG)K
)=LJ select Y from labK
MA',0PN2 LA*PN2 .+),/$8'$2N
############### ######### ####################
7 : physics
:< chemistry
<: " edc
" "! cds
< 7 3a4a lab
)=LJ create table allotment(studPno number(6) references stu(studPno),
matchPno number(6) references lab(machPno),
.o%eek 4archar(!))K
)=LJ desc allotmentK
Name NullZ 'ype
############## ####### #########
)'(.PN2 N(M*+/(6)
MA,0PN2 N(M*+/(6)
.2W++? VA/,0A/(!)
)=LJselect Y from allotmentK
)'(.PN2 MA,0PN2 .2W++?
############### ############ ############
7@ 7 sat
75 <: mon
"< :< tue
< " %ed
5 " thu
c) List all the machine allotments %ith the student names, lab and machine
numbers
)=LJselect s1studname,l1machno from student" s,lab l,allotment a %here
a1machnoRl1machno and a1studnoRs1studnoK
Balaji Institute of Technology and Science 4
Department of Computer Science and Engineering
)'(.NAM+ MA,0N2
LLLLLLLLLLLLLLL11
A*0$&++' "
?ALYAN
A)0W$N 7
A/?A 5
A/V$N. 6
d) List the total number of lab allotments day %ise
)=LJselect l1machno,l1descrip,a1day from lab l,allotment a %here
a1machnoRl1machnoK
MA,0N2 .+),/$8 .AY
LLLLLLLLLLLLLLLLLLLLLLLLLL
" (N$F M2N.AY
(N$F '(+).AY
7 F8 W+.N+).AY
5 W$N.2W) '0/().AY
6 M+ I/$.AY
e) ;i4e a count of ho% many machines ha4e been allocated to the M,)$'G class
)=LJselect count(machno)from allotment %here studno in(select studno from
student" %here classRG,)$'G)K
,2(N' (MA,0N2)
LLLLLLLL11
"
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 MA,0N2 )'(.NAM+ ,LA))
LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
6!7 6 A/V$N. ,)+
g) ,ount for ho% many machines ha4e been allocatedin Lab<no 4 for the
day of the %eek as SMondayT
h) 0o% many students class %ise ha4e allocated machines in the labs
Balaji Institute of Technology and Science 4!
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))
LLLLLLLLLLLLLLLLLLLLLLLLLLLLL
,)+
" +,+
" +++
" $'
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 among
a gi4en set of entity types1

24. 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 eApressed 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
24. 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 5 Definition 'anguage?
'he storage structures and access methods used by database system are
specified 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"
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
1on5$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' <ompiler?
$t translates .ML statements in a Cuery language into lo%#le4el instruction
that the Cuery e4aluation engine can understand1
Balaji Institute of Technology and Science 4#
Department of Computer Science and Engineering
@3' 6rite a program to fin! largest number from the gi$en
three numbers'
#im" 'o find largest number from the gi4en three numbers1
H6;S6 re9uirements"
8rocessor - AM. Athelon D "1B: ;0
E
/AM - 6B M*
0ard .isk - 5! ;*
)oft%are - 2racle, 8l)=L
#lgorithm"
)tep "- .eclare the 4ariable A, *, and ,1
)tep - )tore the 4alid data1
)tep 7- ,ompare 4ariable A %ith * and A %ith ,
)tep 5- $f the 4alue stored in 4ariable A is big, it displays SA is *igT1 ($I
conditional 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(M A is big M)K
+lse
Balaji Institute of Technology and Science 5%
Department of Computer Science and Engineering
$f( bJc [[ bJ a ) then
.bmsPoutput1putPline(M * is big M)K
+lse
.bmsPoutput1putPline(M , is big M)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-
A
+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 eAecutes lo%#le4el instruction generated by compiler1
Balaji Institute of Technology and Science 5$
Department of Computer Science and Engineering
33. What is DD' ,nterpreter?
$t interprets ..L statements and record them in tables containing
metadata1
34. What is -ecord5at5a5time?
'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 Set5at5a5time or Set5oriented?
'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
34. What is -elational <alculus?
$t is an applied predicate calculus specifically tailored for relational
databases proposed by +1I1 ,odd1 +1g1 of languages based on it are .)L AL80A,
=(+L1
Balaji Institute of Technology and Science 52
Department of Computer Science and Engineering
A3' Simple programs using loop: &hile an! for iterati$e
control statement'
a3 'o generate first "! natural numbers using loop: &hile and for1
#IM" 'o generate first "! natural numbers using loop, %hile and for1
H6;S6 re9uirements"
8rocessor - AM. Athelon D "1B: ;0
E
/AM - 6B M*
0ard .isk - 5! ;*
)oft%are - 2racle, 8l)=L
#lgorithm"
)tep "- .eclare the 4ariable $1
)tep - )tore the 4alid data " in $1
)tep 7- (se LOO statement
)tep 5- .isplay the first 4alue1
)tep 6- $ncrement the 4alue of $ by " 4alue1
)tep B- check the 4alue up to "! no1 and repeat the loop
)tep :- $f condition eAceeds the gi4en 4alue "!, the loop %ill be
terminated1
;H using loop statement H;
.eclare
$ numberK
*egin
$-R"K
Loop
.bmsPoutput1putPline($)K
$-R$H"K
+Ait %hen $J"!K
+nd loopK
Balaji Institute of Technology and Science 53
Department of Computer Science and Engineering
+ndK
#lgorithm" for 6HILE loop
)tep "- .eclare the 4ariable $1
)tep - )tore the 4alid data " in $1
)tep 7- (se 6HILE statement
)tep 5- ,heck the 4alue of $ %ith 4alue "!1
)tep 6- if the 4alue of $ reached to "! the loop %ill be terminated
)tep B- other%ise display 4alue of $
)tep :- increment the neAt 4alue of $ using $R$H"1
;H using &hile H;
.eclare
$ numberK
*egin
$-R"K
While ($VR"!)
loop
.bmsPoutput1putPline($)K
$-R$H"K
+nd loopK
+ndK
Balaji Institute of Technology and Science 54
Department of Computer Science and Engineering
#lgorithm"
)tep "- .eclare the 4ariable $1
)tep - )tore the 4alue " in 4ar1 $1
)tep 7- (se *orL LOO statement
)tep 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 loop
)tep :- if the loop eAceeds the 4alue "! then the loop %ill be terminated1
;H using for loopH;
*egin
Ior $ in "11"!
loop
.bmsPoutput1putPline($)K
+nd loopK
+ndK
/ali! (est Data-
O+(+(
"

7
5
6
B
:
<
@
"!
Balaji Institute of Technology and Science 55
Department of Computer Science and Engineering
/i$a-/ice"
36. 0o) does 3uple5oriented relational calculus differ from domain5oriented
relational calculus
'he tuple#oriented calculus uses a tuple 4ariables i1e1, 4ariable %hose only
permitted 4alues are tuples of that relation1 +1g1 =(+L
'he domain#oriented calculus has domain 4ariables i1e1, 4ariables that range o4er
the underlying domains instead of o4er relation1 +1g1 $LL, .+.(,+1
37. What is normali>ation?
$t is a process of analysing the gi4en relation schemas based on their
Iunctional .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 possible
tuple that can form a relation state r of /1 'he constraint is for any t%o tuples t"
and t in r if t"WFX R tWFX then they ha4e t"WYX R tWYX1 'his means the 4alue of
F 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 eCui4alent
to 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 eAist in r such that t"WFX R tWFX
then t7 and t5 should also eAist in r %ith the follo%ing properties
t7WAX R t5WFX R t"WFX R tWFX
t7WYX R t"WYX and t5WYX R tWYX
t7W]X R tW]X and t5W]X R t"W]X
%here W] R (/#(F ( Y)) X

43. What is 'ossless /oin property?
$t guarantees that the spurious tuple generation does not occur %ith
respect to relation schemas after decomposition1
Balaji Institute of Technology and Science 5
Department of Computer Science and Engineering
Balaji Institute of Technology and Science 5!
Department of Computer Science and Engineering
B' rogram to chec8 &hether gi$en number is #rmstrong
or not'
#IM" to check %hether gi4en number is Armstrong or not1
H6;S6 re9uirements"
8rocessor - AM. Athelon D "1B: ;0
E
/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 .(811
)tep 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"!)1
)tep 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 it
in 4ar1 N1
)tep :- repeat the )teps 7, 5, 6, and B till loop %ill be terminated1
)tep <- ,heck %hether the stored 4alue and calculated 4alues are same
)tep @- if both the 4alues are same, then display S'he gi4en number is
ArmstrongT
)tep "!- 2ther%ise display Sit is not ArmstrongT and terminate the
loop1
.eclare
N numberK
) numberK
. numberK
*egin
N-R[nK
)-R!K
While(n^R!)
Loop
.RnU"!K
Balaji Institute of Technology and Science 5"
Department of Computer Science and Engineering
)-RsH(.Y.Y.)K
N-Rfloor(n>"!)K
+nd loopK
$f (.(8R)) then
.*M)Poutput1putPline(Mnumber is armstrongG)K
+lse
.*M)Poutput1putPline(Mnumber 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 non2prime attri&ute , in / is fully
functionally dependent on primary 3ey+
44. What is 3NF?
, relation schema / is in 301 if it is in 201 and for e)ery 1D - , either of the follo4ing is
true
- is a Super23ey of /+
, is a prime attri&ute of /+
In other 4ords( if e)ery non prime attri&ute is non2transiti)ely dependent on primary 3ey+
Balaji Institute of Technology and Science 5#
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 3ey+

47. What is 4NF?
, relation schema / is said to &e in 401 if for e)ery 5ulti)alued dependency - .
that holds o)er /( one of follo4ing is true
- is su&set or e6ual to 'or* -. 7 /+
- is a super 3ey+
Balaji Institute of Technology and Science %
Department of Computer Science and Engineering
0' 6rite a program to generate all prime numbers belo&
4CC'
#IM- to generate all prime numbers belo% "!!1
H6;S6 re9uirements"
8rocessor - AM. Athelon D "1B: ;0
E
/AM - 6B M*
0ard .isk - 5! ;*
)oft%are - 2racle, 8l)=L
.eclare
$ numberK
& numberK
, numberK
*egin
While(iVR"!!)
Loop
,-R!K
&-R"K
While(3VRi)
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 $
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 that
holds /( one the follo4ing is true
/i 7 / for some i+
The join dependency is implied &y the set of 1D( o)er / in 4hich the left side is 3ey 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 3ey 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 4ea3 entities and that are related to same
o4ner entity+ It is sometime called as Discriminator+
(lternate "ey'
,ll Candidate :eys e;cluding the <rimary :ey are 3no4n as ,lternate :eys+
(rti$icial "ey=
If no o&)ious 3ey( either stand alone or compound is a)aila&le( then the last resort is to
simply create a 3ey( &y assigning a uni6ue num&er to each record or occurrence+ Then this is 3no4n as
de)eloping an artificial 3ey+
Compound "ey:
Balaji Institute of Technology and Science 2
Department of Computer Science and Engineering
If no single data element uni6uely identifies occurrences 4ithin a construct( then
com&ining multiple elements to create a uni6ue identifier for the construct is 3no4n as creating a
compound 3ey+
Natural "ey:
>hen one of the data elements stored 4ithin a construct is utili?ed as the primary 3ey(
then it is called the natural 3ey+
53 What is inde)in* and +hat are the di$$erent %inds o$ inde)in*?
Inde;ing is a techni6ue for determining ho4 6uic3ly specific data can &e found+
Types=
Binary search style inde;ing
B2Tree inde;ing
In)erted list inde;ing
5emory resident ta&le
Ta&le inde;ing
Balaji Institute of Technology and Science 3
Department of Computer Science and Engineering
4C' 6rite a program to !emonstrate the ,O(O statement'
#IM- to demonstrate the ;2'2 statement
H6;S6 re9uirements"
8rocessor - AM. Athelon D "1B: ;0
E
/AM - 6B M*
0ard .isk - 5! ;*
)oft%are - 2racle, 8l)=L
.eclare
$ numberK
*egin
$-R"K
$f(iJR!) then
;2'2 hereK
+lse
.bmsPoutput1putPline( M $ is negati4eG)K
+nd ifK
VVhereJJ
.bmsPoutput1putPline( M $ 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
Department of Computer Science and Engineering
, /DB5S maintains a description of all the data that it contains( information a&out e)ery
relation 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 1oin dependency and inclusion dependency?
2oin !ependency'
, @oin dependency is generali?ation of 5ulti)alued dependency+, @D 8/$(
/2( +++( /n9 is said to hold o)er a relation / if /$( /2( /3( +++( /n is a lossless2join decomposition of / +
There is no set of sound and complete inference rules for @D+
3nclusion !ependency'
,n Inclusion Dependency is a statement of the form that some columns of a relation are
contained in other columns+ , foreign 3ey constraint is an e;ample of inclusion dependency+
54 What is dura-ility in !B56?
Ance the DB5S informs the user that a transaction has successfully completed( its effects
should persist e)en if the system crashes &efore all its changes are reflected on dis3+ 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+ Bsers should not ha)e to 4orry a&out the
effect of incomplete transactions+ DB5S ensures this &y undoing the actions of incomplete
transactions+
(**re*ation'
, concept 4hich is used to model a relationship &et4een a collection of entities and
relationships+ It is used 4hen 4e need to e;press a relationship among relationships+
58 What is a &hantom !eadloc%?
In distri&uted deadloc3 detection( the delay in propagating local information might cause the
deadloc3 detection algorithms to identify deadloc3s that do not really e;ist+ Such situations are called
phantom deadloc3s and they lead to unnecessary a&orts+
09 What is a chec%point and When does it occur?
, Chec3point is li3e a snapshot of the DB5S state+ By ta3ing chec3points( the DB5S can
reduce the amount of 4or3 to &e done during restart in the e)ent of su&se6uent crashes+
Balaji Institute of Technology and Science 5
Department of Computer Science and Engineering
44' 6rite a program to !emonstrate Itype an! Iro&type
attributes
#IM- to demonstrate Utype and Uro%type attributes
H6;S6 re9uirements"
8rocessor - AM. Athelon D "1B: ;0
E
/AM - 6B M*
0ard .isk - 5! ;*
)oft%are - 2racle, 8l)=L
.eclare
MyP+mpno emp1empnoUtypeK
MyP+name emp1enameUtypeK
MyP+mpro% empUro%typeK
No numberK
*egin
No-R[noK
)elect empno,ename into myPempno,myPename from emp %here
empnoRnoK
$f()=lUro%countR") then
.bmsPoutput1putPline(Mempno isG __ myPempno __ Mename is M __
myPename)K
+lse
.bmsPoutput1putPline( MerrorG)K
+nd ifK
)elect Y into myPempro% from emp %here empnoRnoK
$f()=lUro%countR") then
.bmsPoutput1putPline(Mempno isG __ myPempro%1empno __ Mename is M __
myPempro%1ename)K
+lse
Balaji Institute of Technology and Science
Department of Computer Science and Engineering
.bmsPoutput1putPline( MerrorG)K
+nd ifK
+ndK
/ali! (est Data
+nter the 4alue for no-
::<<
O+(+(
empno is ::<< ename is 4inay s1
empno is ::<< ename is 4inay s1
/i$a-/ice
01 What are the di$$erent phases o$ transaction?
Different phases are
,nalysis phase
/edo <hase
Bndo phase
02 What do you mean -y $lat $ile data-ase?
It is a data&ase in 4hich there are no programs or user access languages+ It has no cross2file
capa&ilities &ut is user2friendly and pro)ides user2interface management+
03 What is :transparent !B56:?
It is one( 4hich 3eeps its <hysical Structure hidden from user+
04 Brie$ theory o$ Net+or%# ,ierarchical schemas and their properties
0et4or3 schema uses a graph data structure to organi?e records e;ample for such a data&ase
management system is CTCC 4hile a hierarchical schema uses a tree data structure e;ample for such a
system is I5S+
05 What is a .uery?
, 6uery 4ith respect to DB5S relates to user commands that are used to interact 4ith a data
&ase+ The 6uery language can &e classified into data definition language and data manipulation
language+
00 What do you mean -y Correlated su-.uery?
Su&6ueries( or nested 6ueries( are used to &ring &ac3 a set of ro4s to &e used &y the parent
6uery+ Depending on ho4 the su&6uery is 4ritten( it can &e e;ecuted once for the parent 6uery or it can
&e e;ecuted once for each ro4 returned &y the parent 6uery+ If the su&6uery is e;ecuted for each ro4 of
the parent( this is called a correlated su-.uery+
Balaji Institute of Technology and Science !
Department of Computer Science and Engineering
, correlated su&6uery can &e easily identified if it contains any references to the parent
su&6uery columns in its >DE/E clause+ Columns from the su&6uery cannot &e referenced any4here
else in the parent 6uery+ The follo4ing e;ample demonstrates a non2correlated su&6uery+
E+g+ Select E 1rom CBST >here F$%G%3G$##%F I0 'Select AD,TE 1rom A/DE/ >here
CBST+C0B5 7 A/DE/+C0B5*
04 What are the primiti;e operations common to all record mana*ement systems?
,ddition( deletion and modification+
Balaji Institute of Technology and Science "
Department of Computer Science and Engineering
41' 6rite a program to !emonstrate pre!efine! e7ceptions
#IM- to demonstrate predefined eAceptions
H6;S6 re9uirements"
8rocessor - AM. Athelon D "1B: ;0
E
/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(Mdi4ision is M __ ,)K
+Aception
$f (]+/2P.$V$.+) then
.bmsPoutput1putPline(Mb 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 #
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
Edit Buffer
08 What are the unary operations in <elational (l*e-ra?
</A@ECTIA0 and SEHECTIA0+
49 (re the resultin* relations o$ &<=!>C? and 2=3N operation the same?
0o+
&<=!>C?= Concatenation of e)ery ro4 in one relation 4ith e)ery ro4 in another+
2=3N= Concatenation of ro4s from one relation and related ro4s from another+
41 What is <!B56 "@<N@A?
T4o important pieces of /DB5S architecture are the 3ernel( 4hich is the soft4are( and the
data dictionary( 4hich consists of the system2le)el data structures used &y the 3ernel to manage the
data&ase
.ou might thin3 of an /DB5S as an operating system 'or set of su&systems*( designed
specifically for controlling data accessI its primary functions are storing( retrie)ing( and securing data+
,n /DB5S maintains its o4n list of authori?ed users and their associated pri)ilegesI manages
memory caches and pagingI controls loc3ing for concurrent resource usageI dispatches and schedules
user re6uestsI and manages space usage 4ithin its ta&le2space structures
+
42 Name the su--systems o$ a <!B56
IGA( Security( Hanguage <rocessing( <rocess Control( Storage 5anagement( Hogging and
/eco)ery( Distri&ution Control( Transaction Control( 5emory 5anagement( Hoc3 5anagement
43 Which part o$ the <!B56 ta%es care o$ the data dictionary? ,o+
Data dictionary is a set of ta&les and data&ase o&jects that is stored in a special area of the
data&ase and maintained e;clusi)ely &y the 3ernel+
44 What is the 1o- o$ the in$ormation stored in data-dictionary?
The information in the data dictionary )alidates the e;istence of the o&jects( pro)ides access to
them( and maps the actual physical storage location+
4>' 6rite a program to !emonstrate user !efine!
e7ceptions
#IM- to demonstrate user defined eAceptions
H6;S6 re9uirements"
Balaji Institute of Technology and Science !%
Department of Computer Science and Engineering
8rocessor - AM. Athelon D "1B: ;0
E
/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(Mdi4ision is M __ ,)K
+nd ifK
+Aception
$f (mydi4idePEero) then
.bmsPoutput1putPline(Mb could not be EeroG)K
+nd ifK
+ndK
/ali! (est Data"
+nter the 4alue for a-
Balaji Institute of Technology and Science !$
Department of Computer Science and Engineering
"!
+nter the 4alue for b-
!
O+(+("
b could not be Eero
/i$a-/ice"
45 Not only <!B56 ta%es care o$ locatin* data it also
determines an optimal access path to store or retrie)e the data
40 ,o+ do you communicate +ith an <!B56?
.ou communicate 4ith an /DB5S using Structured Juery Hanguage 'SJH*
44 !e$ine 6BA and state the di$$erences -et+een 6BA and other con;entional pro*rammin*
Aan*ua*es
SJH is a nonprocedural language that is designed specifically for data access operations on
normali?ed relational data&ase structures+ The primary difference &et4een SJH and other con)entional
programming languages is that SJH statements specify 4hat data operations should &e performed
rather than ho4 to perform them+
47 Name the three ma1or set o$ $iles on dis% that compose a data-ase in =racle
There are three major sets of files on dis3 that compose a data&ase+ ,ll the files are &inary+ These are
Data&ase files
Control files
/edo logs
The most important of these are the data&ase files 4here the actual data resides+ The control
files and the redo logs support the functioning of the architecture itself+
,ll three sets of files must &e present( open( and a)aila&le to Aracle for any data on the data&ase to &e usea&le+ >ithout these files( you cannot
access the data&ase( and the data&ase administrator might ha)e to reco)er some or all of the data&ase using a &ac3up( if there is one+
48 What is an =racle 3nstance?
The Aracle system processes( also 3no4n as Aracle &ac3ground processes( pro)ide functions
for the user processesKfunctions that 4ould other4ise &e done &y the user processes themsel)es
Aracle data&ase24ide system memory is 3no4n as the SC,( the system *lo-al area or shared
*lo-al area+ The data and control structures in the SC, are sharea&le( and all the Aracle &ac3ground
processes and user processes can use them+
The com&ination of the SC, and the Aracle &ac3ground processes is 3no4n as an =racle
instance
79 What are the $our =racle system processes that must al+ays -e up and runnin* $or the data-ase to
-e usea-le
The four Aracle system processes that must al4ays &e up and running for the data&ase to &e
usea&le include !BW< 'Data&ase >riter*( ACW< 'Hog >riter*( 65=N 'System 5onitor*( and &5=N
'<rocess 5onitor*+
Balaji Institute of Technology and Science !2
Department of Computer Science and Engineering
Balaji Institute of Technology and Science !3
Department of Computer Science and Engineering
4?' Create a Cursor &hich up!ate the salaries of an Employee
as follo&s'
"1 if salV"!!!then update the salary to "6!!1
1 if salJR"!!! and V!!! then update the salary to 6!!1
71 if salJR!!! and VR7!!! then update the salary to 5!!!1
And also count the no1of records ha4e been updated1Y>
H6;S6 re9uirements"
8rocessor - AM. Athelon D "1B: ;0
E
/AM - 6B M*
0ard .isk - 5! ;*
)oft%are - 2racle, 8l)=L
.eclare
,ursor myPcur is select empno,sal from empK
Fno emp1empnoUtypeK
Fsal emp1salUtypeK
, numberK
*egin
2pen myPcurK
,-R!K
Loop
Ietch myPcur into Ano,AsalK
$f(AsalV"!!!) then
(pdate emp set salR7!!! %here empnoRAnoK
,-RcH"K
+lse if(AsalJR!!!) and AsaV7!!!) then
Balaji Institute of Technology and Science !4
Department of Computer Science and Engineering
(pdate emp set salR5!!! %here empnoRAnoK
,-RcH"K
+nd ifK
+nd ifK
+Ait %hen myPcurUN2'I2(N. K
+nd loopK
,lose myPcurK
.bmaPoutput1putPline(c__Grecords ha4e been successfully updatedG)K
+ndK
)ClJNa1sClK
records ha4e been successfully updated
pl>sCl procedure successfully completed1
/ali! (est Data
*efore eAecuting the cursor, the records in emp table as follo%s
)ClJselect Y from empK
O+(+("
+M8N2 +NAM+ &2* M;/ 0$/+.A'+ )AL ,2MM. +8'N2
#################################################################
:7B@ )M$'0 ,L+/? :@! ":#.+,#<! !!! !
:5@@ ALL+N )AL+)MAN :B@< !#I+*#<" "B!! 7!! 7!
:6" WA/. )AL+)MAN :B@< #I+*#<" "6! 6!! 7!
+M8N2 +NAM+ &2* M;/ 0$/+.A'+ )AL ,2MM .+8'N2
######## ########## ######### ########## ######### ##########
########################################
:6BB &2N+) MANA;+/ :<7@ !#A8/#<" @:6 !
Balaji Institute of Technology and Science !5
Department of Computer Science and Engineering
:B65 MA/'$N )AL+)MAN :B@< <#)+8#<" "6! "5!! 7!
:B@< *LA?+ MANA;+/ :<7@ !"#MAY#<" <6! 7!
L
L1
L
"5 ro%s selected1
/i$a-/ice"
71 What are data-ase $iles# control $iles and lo* $iles ,o+ many o$ these $iles should a data-ase ha;e
at least? Why?
!ata-ase Files
The data&ase files hold the actual data and are typically the largest in si?e+ Depending
on their si?es( the ta&les 'and other o&jects* for all the user accounts can go in one data&ase fileK&ut
thatFs not an ideal situation &ecause it does not ma3e the data&ase structure )ery fle;i&le for controlling
access to storage for different users( putting the data&ase on different dis3 dri)es( or &ac3ing up and
restoring just part of the data&ase+
You must have at least one database fle but usually, more than one
fles are used. In terms of accessing and using the data in the tables and other
objects, the number (or location) of the fles is immaterial.
The data&ase files are fi;ed in si?e and ne)er gro4 &igger than the si?e at 4hich they
4ere created
Control Files
The control files and redo logs support the rest of the architecture+ ,ny data&ase
must ha)e at least one control file( although you typically ha)e more than one to guard against loss+
The control file records the name of the data&ase( the date and time it 4as created( the location of
the data&ase and redo logs( and the synchroni?ation information to ensure that all three sets of files
are al4ays in step+ E)ery time you add a ne4 data&ase or redo log file to the data&ase( the
information is recorded in the control files+
<edo Ao*s
,ny data&ase must ha)e at least t4o redo logs+ These are the journals for the data&aseI
the redo logs record all changes to the user o&jects or system o&jects+ If any type of failure occurs( the
changes recorded in the redo logs can &e used to &ring the data&ase to a consistent state 4ithout losing
any committed transactions+ In the case of non2data loss failure( Aracle can apply the information in
the redo logs automatically 4ithout inter)ention from the DB,+
The redo log files are fi;ed in si?e and ne)er gro4 dynamically from the si?e at 4hich
they 4ere created+
Balaji Institute of Technology and Science !
Department of Computer Science and Engineering
72 What is <=W3!?
The /A>ID is a uni6ue data&ase24ide physical address for e)ery ro4 on e)ery ta&le+ Ance
assigned '4hen the ro4 is first inserted into the data&ase*( it ne)er changes until the ro4 is deleted or
the ta&le is dropped+
The /A>ID consists of the follo4ing three components( the com&ination of 4hich uni6uely
identifies the physical storage location of the ro4+
Aracle data&ase file num&er( 4hich contains the &loc3 4ith the ro4s
Aracle &loc3 address( 4hich contains the ro4
The ro4 4ithin the &loc3 '&ecause each &loc3 can hold many ro4s*
The /A>ID is used internally in inde;es as a 6uic3 means of retrie)ing ro4s 4ith a particular
3ey )alue+ ,pplication de)elopers also use it in SJH statements as a 6uic3 4ay to access a ro4 once
they 3no4 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 &loc3s 4hen they are first created
Kma3ing it easier for the /DB5S soft4are to manage the files and easier to read data into the
memory areas+
The &loc3 si?e should &e a multiple of the operating system &loc3 si?e+ /egardless of the &loc3
si?e( the entire &loc3 is not a)aila&le for holding dataI Aracle ta3es up some space to manage the
contents of the &loc3+ This &loc3 header has a minimum si?e( &ut it can gro4+
These Aracle &loc3s are the smallest unit of storage+ Increasing the Aracle &loc3 si?e can
impro)e performance( &ut it should &e done only 4hen the data&ase is first created+
Each Aracle &loc3 is num&ered se6uentially for each data&ase file starting at $+ T4o &loc3s can
ha)e the same &loc3 address if they are in different data&ase files+
74 What is data-ase ?ri**er?
, data&ase trigger is a <HGSJH &loc3 that can defined to automatically e;ecute for insert(
update( and delete statements against a ta&le+ The trigger can e defined to e;ecute once for the entire
statement or once for e)ery ro4 that is inserted( updated( or deleted+ 1or any one ta&le( there are t4el)e
e)ents for 4hich you can define data&ase triggers+ , data&ase trigger can call data&ase procedures that
are also 4ritten in <HGSJH+
75 Name t+o utilities that =racle pro;ides# +hich are use $or -ac%up and reco;ery
,long 4ith the /DB5S soft4are( Aracle pro)ides t4o utilities that you can use to &ac3 up and
restore the data&ase+ These utilities are @)port and 3mport+
The @)port utility dumps the definitions and data for the specified part of the data&ase to an
operating system &inary file+ The 3mport 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 &ac3ing up and reco)ering the data&ase( all the
changes made to the data&ase cannot &e reco)ered since the e;port 4as performed+ The &est you can
do is reco)er the data&ase to the time 4hen the e;port 4as last performed+
Balaji Institute of Technology and Science !!
Department of Computer Science and Engineering
40' create a proce!ure &hich generate all the prime
numbers belo& the gi$en number an! count the no'of
prime numbers'
H6;S6 re9uirements"
8rocessor - AM. Athelon D "1B: ;0
E
/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(iVRn)
loop
3-R"K
c-R!K
%hile(3VRi)
loop
if(mod($,3)R!) then
c-RcH"K
end ifK
Balaji Institute of Technology and Science !"
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(Mthe total prime no 1areG__t)K
endK
/ali! (est Data"
sClJset ser4eroutput on
O+(+(
sClJ>

7
6
Balaji Institute of Technology and Science !#
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 4ith the /DB5S soft4are( Aracle pro)ides t4o utilities that you can use to &ac3 up and
restore the data&ase+ These utilities are @)port and 3mport+
The @)port utility dumps the definitions and data for the specified part of the data&ase to an
operating system &inary file+ The 3mport 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 &ac3ing up and reco)ering the data&ase( all the
changes made to the data&ase cannot &e reco)ered since the e;port 4as performed+ The &est you can
do is reco)er the data&ase to the time 4hen the e;port 4as last performed+
74 What are stored-procedures? (nd +hat are the ad;anta*es o$ usin* them
Stored 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 net4or3 traffic+
77 ?a-les deri;ed $rom the @<!
a* ,re totally unnormalised
&* ,re al4ays in $01
c* Can &e further denormalised
d* 5ay ha)e multi2)alued attri&utes
'&* ,re al4ays in $01
78 6purious tuples may occur due to
i Bad normali/ation
ii ?heta 1oins
iii >pdatin* ta-les $rom 1oin
a* 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 3eys that are not primary 3eys+
89 ( B C is a set o$ attri-utes ?he $unctional dependency is as $ollo+s
(B -D B
(C -D C
C -D B
a* is in $01
&* is in 201
c* is in 301
d* is in BC01
Balaji Institute of Technology and Science "%
Department of Computer Science and Engineering
'a* is in $01 since ',C*
N
7 8 ,( B( C9 hence ,C is the primary 3ey+ Since C B is a 1D
gi)en( 4here 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 3ey ,C thus it is not in 201+ Thus the gi)en 1Ds is in $01+
Balaji Institute of Technology and Science "$
Department of Computer Science and Engineering
4B' create a proce!ure &hich up!ates the salaries of an
employees as follo&s'
"1if salV"!!! then update the salry to "6!!1
1if salJR"!!! and VR5!! then update the salary to 6!!1Y>
H6;S6 re9uirements"
8rocessor - AM. Athelon D "1B: ;0
E
/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 Ano,AsalK
$f(AsalV"!!!) then
(pdate emp set salR"6!! %here empnoRAnoK
,-RcH"K
+lse
$s(AsalJR"!!! and AsalVR5!!) then
(pdate emp set salR6!! %here empnoRAnoK
Balaji Institute of Technology and Science "2
Department of Computer Science and Engineering
,-RcH"K
+nd ifK
+nd ifK
+Ait %hen myPcurUN2'I2(N.K
+nd loopK
,lose myPcurK
.bmsPoutput1putPline(c__Grecords ha4e been successfully updatedG)K
+ndK
>
/ali! (est Data"
8rocedure created1
)ClJeAec myprocK
O+(+("
/ecords ha4e been successfully completed1
>Y create function %hich add t%o gi4en numbers1 ()imple programs) Y>
,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
Department of Computer Science and Engineering
Iunction created1
>YaddPfun specificationY>
.eclare
/esult numberK
*egin
/esult-RaddPfun("!,!)K
.bmsPoutput1putPline(Mthe sum of "! and ! isG__result)K
+ndK
)ClJ>
'he sum of "! and ! is 7!
8l>sCl procedure successfully completed1
>Ycreate a function %hich count total no1of employees ha4ing salary less
than B!!!1Y>
>Yfunction bodyY>
,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
Department of Computer Science and Engineering
fetch 4inPcur into Ano,AsalK
if(AsalVesal) then
c-RcH"K
end ifK
eAit %hen 4inPcurUnotfoundK
end loopK
close 4inPcurK
return cK
endK
>
Iunction created1
>Yfunction specificationY>
.eclare
Ne numberK
Fsal numberK
*egin
Ne-RcountPemp(Asal)K
.bmsPoutput1putPline(Asal)K
.bmaPoutput1putPline(Mthere are M__ne__KemployeesG)K
+ndK
>
O+(+(
'here are < employees1
/i$a-/ice"
Balaji Institute of Technology and Science "5
Department of Computer Science and Engineering
81 3n mappin* o$ @<! to !F!
a* entities in E/D should correspond to an e;isting entityGstore in D1D
&* 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 D1D
d* relationships in E/D has $ to $ correspondence to flo4s 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 relationship
c* on either side in a $ = $ relationship
d* nothing to do 4ith $ = $ or $ = 0 relationship
'&* on the $ side in a $ = 0 relationship
83 6elect EN=<?,E# C>6?=5@< From C>6?F!?A6 Where <@C3=N G ENE =rder By
C>6?=5@< >nion 6elect E@(6?E# C>6?=5@< From C>6?F!?A6 Where <@C3=N G E@E =rder
By C>6?=5@<
The a&o)e is
a* 0ot an error
&* Error 2 the string in single 6uotes F0A/TDF and FSABTDF
c* Error 2 the string should &e in dou&le 6uotes
d* Error 2 A/DE/ B. clause
'd* Error 2 the A/DE/ B. clause+ Since A/DE/ B. clause cannot &e used in B0IA0S
84 What is 6tora*e 5ana*er?
It is a program module that pro)ides the interface &et4een the lo42le)el data stored in
data&ase( application programs and 6ueries su&mitted to the system+

85 What is Bu$$er 5ana*er?
It is a program module( 4hich is responsi&le for fetching data from dis3 storage into main
memory and deciding 4hat data to &e cache in memory+
80 What is ?ransaction 5ana*er?
It is a program module( 4hich ensures that data&ase( remains in a consistent state despite
system failures and concurrent transaction e;ecution proceeds 4ithout conflicting+
84 What is File 5ana*er?
It is a program module( 4hich manages the allocation of space on dis3 storage and data
structure used to represent information stored on a dis3+
87 What is (uthori/ation and 3nte*rity mana*er?
It is the program module( 4hich tests for the satisfaction of integrity constraint and chec3s the
authority of user to access data+

88 What are stand-alone procedures?
<rocedures that are not part of a pac3age are 3no4n as stand2alone &ecause they independently
defined+ , good e;ample of a stand2alone procedure is one 4ritten in a SJHE1orms application+ These
Balaji Institute of Technology and Science "
Department of Computer Science and Engineering
types of procedures are not a)aila&le for reference from other Aracle tools+ ,nother limitation of stand2
alone procedures is that they are compiled at run time( 4hich slo4s e;ecution+
199 What are cursors *i;e di$$erent types o$ cursors
<HGSJH uses cursors for all data&ase information accesses statements+ The language
supports the use t4o types of cursors
3mplicit
@)plicit
191 What is cold -ac%up and hot -ac%up (in case o$ =racle)?
Cold Bac%up'
It is copying the three sets of files 'data&ase files( redo logs( and control file* 4hen
the instance is shut do4n+ This is a straight file copy( usually from the dis3 directly to tape+ .ou must
shut do4n the instance to guarantee a consistent copy+
If a cold &ac3up is performed( the only option a)aila&le in the e)ent of data file loss
is restoring all the files from the latest &ac3up+ ,ll 4or3 performed on the data&ase since the last
&ac3up is lost+
,ot Bac%up'
Some sites 'such as 4orld4ide airline reser)ations systems* cannot shut do4n the
data&ase 4hile ma3ing a &ac3up copy of the files+ The cold &ac3up is not an a)aila&le option+
So different means of &ac3ing up data&ase must &e used K the hot &ac3up+ Issue a
SJH command to indicate to Aracle( on a ta&lespace2&y2ta&lespace &asis( that the files of the
ta&lespace are to &ac3ed up+ The users can continue to ma3e full use of the files( including ma3ing
changes to the data+ Ance the user has indicated that heGshe 4ants to &ac3 up the ta&lespace files(
heGshe can use the operating system to copy those files to the desired &ac3up destination+
The data&ase must &e running in ,/CDIOEHAC mode for the hot &ac3up option+
If a data loss failure does occur( the lost data&ase files can &e restored using the hot
&ac3up and the online and offline redo logs created since the &ac3up 4as done+ The data&ase is
restored to the most consistent state 4ithout any loss of committed transactions+
192 What are (rmstron* rules? ,o+ do +e say that they are complete andHor sound
The 4ell23no4n inference rules for 1Ds
/efle;i)e rule =
If . is su&set or e6ual to - then - .+
,ugmentation rule=
If - . then -P .P+
Transiti)e rule=
If 8- .( . P9 then - P+
Decomposition rule =
If - .P then - .+
Bnion or ,dditi)e rule=
If 8- .( - P9 then - .P+
<seudo Transiti)e rule =
If 8- .( >. P9 then >- P+
Af these the first three are 3no4n as ,mstrong /ules+ They are sound &ecause it is enough if a
set of 1Ds satisfy these three+ They are called complete &ecause using these three rules 4e can generate
the rest all inference rules+
193 ,o+ can you $ind the minimal %ey o$ relational schema?
Balaji Institute of Technology and Science "!
Department of Computer Science and Engineering
5inimal 3ey is one 4hich can identify each tuple of the gi)en relation schema uni6uely+ 1or
finding the minimal 3ey it is re6uired to find the closure that is the set of all attri&utes that are
dependent on any gi)en set of attri&utes under the gi)en set of functional dependency+
Algo. I Determining -
N
( closure for -( gi)en set of 1Ds 1
$+
Set -
N
7 -
2+
Set Ald -
N 7
-
N
3+
1or each 1D . P in 1 and if . &elongs to -
N
then add P to -
N
4+
/epeat steps 2 and 3 until Ald -
N
7 -
N
Algo.II Determining minimal : for relation schema /( gi)en set of 1Ds 1
$+ Set : to / that is ma3e : a set of all attri&utes in /
2+ 1or each attri&ute , in :
a+
Compute ': Q ,*
N
4ith respect to 1
&+
If ': Q ,*
N
7 / then set : 7 ': Q ,*
N
194 What do you understand -y dependency preser;ation?
Ci)en a relation / and a set of 1Ds 1( dependency preser)ation states that the closure of
the union of the projection of 1 on each decomposed relation /i is e6ual to the closure of 1+ i+e+(
''/$'1** B R B '/n'1***
N
7 1
N

if decomposition is not dependency preser)ing( then some dependency is lost in the decomposition+

195 What is meant -y &roacti;e# <etroacti;e and 6imultaneous >pdate
&roacti;e >pdate'
The updates that are applied to data&ase &efore it &ecomes effecti)e in real
4orld +
<etroacti;e >pdate'
The updates that are applied to data&ase after it &ecomes effecti)e in real 4orld +
6imulatneous >pdate'
The updates that are applied to data&ase at the same time 4hen it &ecomes
effecti)e in real 4orld +
190 What are the di$$erent types o$ 2=3N operations?
@.ui 2oin' This is the most common type of join 4hich in)ol)es only e6uality
comparisions+ The disad)antage in this type of join is that there
Balaji Institute of Technology and Science ""
Department of Computer Science and Engineering
SDL Duestions"
1 Which is the su-set o$ 6BA commands used to manipulate =racle !ata-ase structures# includin*
ta-les?
Data Definition Hanguage 'DDH*
2 What operator per$orms pattern matchin*?
HI:E operator
3 What operator tests column $or the a-sence o$ data?
IS 0BHH operator
4 Which command e)ecutes the contents o$ a speci$ied $ile?
ST,/T SfilenameT or USfilenameT
5 What is the parameter su-stitution sym-ol used +ith 3N6@<? 3N?= command?
M
0 Which command displays the 6BA command in the 6BA -u$$er# and then e)ecutes it?
/B0
4 What are the +ildcards used $or pattern matchin*?
V for single character su&stitution and W for multi2character su&stitution
7 6tate true or $alse @I36?6# 6=5@# (NJ are operators in 6BA
True
8 6tate true or $alse KG# LD# MG all denote the same operation
True
19 What are the pri;ile*es that can -e *ranted on a ta-le -y a user to others?
Insert( update( delete( select( references( inde;( e;ecute( alter( all
11 What command is used to *et -ac% the pri;ile*es o$$ered -y the C<(N? command?
/EOA:E
12 Which system ta-les contain in$ormation on pri;ile*es *ranted and pri;ile*es o-tained?
BSE/VT,BV</IOSV5,DE( BSE/VT,BV</IOSV/ECD
13 Which system ta-le contains in$ormation on constraints on all the ta-les created?
BSE/VCA0ST/,I0TS
14 ?<>NC(?@ ?(BA@ @5&N
!@A@?@ F<=5 @5&N
Will the outputs o$ the a-o;e t+o commands di$$er?
Both 4ill result in deleting all the ro4s in the ta&le E5<+
15 What is the di$$erence -et+een ?<>NC(?@ and !@A@?@ commands?
Balaji Institute of Technology and Science "#
Department of Computer Science and Engineering
T/B0C,TE is a DDH command 4hereas DEHETE is a D5H command+ Dence DEHETE
operation can &e rolled &ac3( &ut T/B0C,TE operation cannot &e rolled &ac3+ >DE/E clause can &e
used 4ith DEHETE and not 4ith T/B0C,TE+
10 What command is used to create a ta-le -y copyin* the structure o$ another ta-le?
Answer :
C/E,TE T,BHE ++ ,S SEHECT command
Explanation :
To copy only the structure( the >DE/E clause of the SEHECT command should contain a
1,HSE statement as in the follo4ing+
C/E,TE T,BHE 0E>T,BHE ,S SEHECT E 1/A5 E-ISTI0CT,BHE >DE/E $72I
If the >DE/E condition is true( then all the ro4s or ro4s satisfying the condition 4ill &e
copied to the ne4 ta&le+
14 What +ill -e the output o$ the $ollo+in* .uery?
SELECT REPLACE(TRANSLATE(LTRIM(RTRIM('!! ATHEN !!','!'), '!'), 'AN',
'**'),'*','TROUBLE') FROM DUAL;
T/ABBHETDET/ABBHE
17 What +ill -e the output o$ the $ollo+in* .uery?
6@A@C? !@C=!@(?<(N6A(?@(E(E#E1234504789E#E1111111111E)# E1E#EJ@6E# EN=E )N
Answer :
0A
Explanation :
The 6uery chec3s 4hether a gi)en string is a numerical digit+
18 What does the $ollo+in* .uery do?
6@A@C? 6(A O NPA(C=55#9) F<=5 @5&N
This displays the total salary of all employees+ The null )alues in the commission column 4ill
&e replaced &y % and added to salary+
29 Which date $unction is used to $ind the di$$erence -et+een t+o dates?
5A0TDSVBET>EE0
21 Why does the $ollo+in* command *i;e a compilation error?
!<=& ?(BA@ Q?(BA@FN(5@N
Oaria&le names should start 4ith an alpha&et+ Dere the ta&le name starts 4ith an FMF sym&ol+
22 What is the ad;anta*e o$ speci$yin* W3?, C<(N? =&?3=N in the C<(N? command?
The pri)ilege recei)er can further grant the pri)ileges heGshe has o&tained from the o4ner to
any other user+
23 What is the use o$ the !<=& option in the (A?@< ?(BA@ command?
It is used to drop constraints specified on the ta&le+
24 What is the ;alue o$ RcommS and RsalS a$ter e)ecutin* the $ollo+in* .uery i$ the initial ;alue o$ RsalS
is 19999?
>&!(?@ @5& 6@? 6(A G 6(A O 1999# C=55 G 6(AT91N
sal 7 $$%%%( comm 7 $%%%
Balaji Institute of Technology and Science #%
Department of Computer Science and Engineering
25 What is the use o$ !@6C in 6BA?
Answer :
DESC has t4o purposes+ It is used to descri&e a schema as 4ell as to retrie)e ro4s from ta&le
in descending order+
Explanation :
The 6uery SEHECT E 1/A5 E5< A/DE/ B. E0,5E DESC 4ill display the output sorted
on E0,5E in descending order+
20 What is the use o$ C(6C(!@ C=N6?<(3N?6?
>hen this clause is used 4ith the D/A< command( a parent ta&le can &e dropped e)en 4hen a
child ta&le e;ists+
24 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(12345047#-2) F<=5 !>(AN
$2%%
Balaji Institute of Technology and Science #$
Department of Computer Science and Engineering
%E*E%E)CES"
),2'' (rman, oracle <i#8L>)=L programming,'M0#!!!
Loney, oracle <i#the complete reference,'M0#!!!
Loney, oracle @i#the complete reference,'M0#!!!
*ayross, oracle 'each Your )elf )=L>8L)=L using oracle <i and @i %ith
)=L&, *8*, !!1
Abbey, oracle <i#A beginners guide,'M0#!!!1
Balaji Institute of Technology and Science #2
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
" <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Class ; Kear ;
Semester
"
B' (ech <<<<< Kear <<<<<<<<< Semester
%oll )o'
" <<<<<<<<<<<<<<<<<<<<<<<<<
SubEect
" <<<<<<<<<<<<<<<<<<<<<<<<<
Branch
" <<<<<<<<<<<<<<<<<<<<<<<<<
Date of
Submission
" <<<<< ; <<<<< ; <<<<<<<<<<
<<<<<<<<<<<<<<<< <<<<<<<<<<<<<<<<
Stu!ent Signature *aculty Signature
Balaji Institute of Technology and Science #3
#nne7ure - 4
Department of Computer Science and Engineering
In!e7 age
S' )o' Date rogram ; E7periment
age
)o'
Sign ;
%emar8s
Balaji Institute of Technology and Science #4
#nne7ure - 1
#nne7ure - =
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
" <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Class ; Kear ;
Semester
"
B' (ech <<<<<< Kear <<<<<<<< Semester
%oll )o'
" <<<<<<<<<<<<<<<<<<<<<<<<<
SubEect
" <<<<<<<<<<<<<<<<<<<<<<<<<
Branch
" <<<<<<<<<<<<<<<<<<<<<<<<<
Has successfully complete! the course of programs ;
e7periments prescribe! by .a&harlal )erhu
(echnological +ni$eristy of the !epartment !uring the
aca!emic year 1CC<< - 1CC <<'
<<<<<<<<<<<<<<<< <<<<<<<<<<<<<<<<
*aculty Incharge Department Hea!
Balaji Institute of Technology and Science #5

You might also like