P. 1
Dbms Lab Manual

Dbms Lab Manual

|Views: 2,734|Likes:

More info:

Published by: GanBrave Ganesh Maragani on Jul 21, 2011
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less

04/21/2013

pdf

text

original

GURU NANAK Engineering College

Ibrahimpatnam, R R District – 501 506 (A. P.)

Department of Computer Science Engineering Database Management Systems Lab Manual [CS 05157]
II B Tech – I Semester [Branch: CSE]
INSTRUCTORS :

Mr. Rishi Sayal, HOD Mr. Saidulu, Asst. Prof.

Document NO:

Date of Issue:

Compiled by

Authorized by

GNEC/CSE/LAB MANUAL/DBMS
Date of revision Verified by

PROGRAMMERS

:

1. K.Ravi 2. Triveni Joshi

DBMS Lab Manual

INDEX

S. No 1 2 3 3 4 5 6 7 8 9 10

Contents Lab Objective Introduction About Lab Standard Operating Procedure – SOP Guidelines to Students Description about SQL, PL/SQL statements and D2K. List of Lab Exercises 4.1 Syllabus Programs (JNTU) 4.2 Additional Programs Background Theory Solutions for Programs PL-Sql Programs Additional Viva Question References

Page. no 3 4 6 7 8 9 14 20 50 88 94

K.Ravi

2

DBMS Lab Manual

LAB OBJECTIVE
Upon successful completion of this Lab the student will be able to:  Creating database objects  Modifying database objects  Manipulating the data  Retrieving the data from the database server  Performing database operations in a procedural manner using pl/sql  Performing database operations (create, update, modify, retrieve, etc.,) using front-end tools like D2K.  Design and Develop applications like banking, reservation system, etc.,

K.Ravi

3

Their configurations are as follows : Processor RAM Hard Disk Mouse : : : : AMD Athelon ™ 1. account for each student has been created.e. data related projects.  Each student has a separate login for database access Oracle 9i client version is installed in all systems. Students can boot from Windows XP or Linux as per their lab requirement. etc) in their own accounts. Each student work is safe and secure from other students. This is very useful because students can save their work (scenarios’. This is very useful for students because they are familiar with different Operating Systems so that they can execute their programs in different programming environments.Ravi 4 .DBMS Lab Manual INTRODUCTION ABOUT LAB There are 66 systems ( Compaq Presario ) installed in this Lab. pl / sql programs. K.67 GHz 256 MB 40 GB Optical Mouse Present Network Interface card : Software  All systems are configured in DUAL BOOT mode i.. On the server.

DBMS Lab Manual  Latest Technologies like DOT NET and J2EE are installed in some systems. Before submitting their final project, they can start doing mini project from 2nd year onwards.

 MASM (Macro Assembler) is installed in all the systems Students can execute their assembly language programs using MASM. MASM is very useful students because when they execute their programs they can see contents of Processor Registers and how each instruction is being executed in the CPU.

 Rational Rose Software is installed in some systems Using this software, students can depict UML diagrams of their projects.  Softwares installed : C, C++, JDK1.5, MASM, OFFICE-XP, J2EE and DOT NET, Rational Rose.

 Systems are provided for students in the 1:1 ratio.  Systems are assigned numbers and same system is allotted for students when they do the lab.

K.Ravi

5

DBMS Lab Manual

STANDARD OPERATING PROCEDURE – SOP
a) Explanation on today’s experiment by the concerned faculty using OHP/PPT covering the following aspects: 25 mins. 1) 2) 3) 4) 1) 2) Name of the experiment/Aim Software/Hardware required Algorithm Test Data Valid data sets Limiting value sets 3) Invalid data sets b) Writing of source program by the students min. c) Compiling and execution of the program 25

100 mins. Writing of the experiment in the Observation Book: The students will write the today’s experiment in the Observation book as per the following format: a) b) c) d) e) a. b. c. f) K.Ravi Name of the experiment/Aim Software/Hardware required Algorithm Source Program Test Data Valid data sets Limiting value sets Invalid data sets Results for different data sets 6

DBMS Lab Manual g) h) i) Viva-Voc Questions and Answers Errors observed (if any) during compilation/execution Signature of the Faculty

K.Ravi

7

 Students are not supposed to use floppy disks K. Students need to maintain a proper decorum in the computer lab.  Students are required to carry their observation / programs book with completed exercises while entering the lab. Students must use the equipment with care.  Students are supposed to occupy the machines allotted to them and are not supposed to talk or make noise in the lab.Ravi 8 .  Lab records need to be submitted on or before date of submission.DBMS Lab Manual Guidelines to Students  Equipment in the lab for the use of student community. The allocation is put up on the lab notice board. Any damage is caused is punishable.  Lab can be used in free time / lunch hours by the students who need to use the systems should take prior permission from the lab incharge.

2 sal from 3 emp.DBMS Lab Manual How to Write and execute sql. if you want to edit the previous command then you have to open sql editor (by default it displays the sql buffer contents). Upon successful login you will get SQL prompt (SQL>). If you type your programs at sql prompt then screen will look like follow: SQL> SELECT ename. K. By giving ‘ed’ at sql prompt. or in sql editor. This how we can write. Always you have to save your programs in your own logins. To execute the program which saved.sql Then press ‘\’ key and enter.->application development->sql. where 2 and 3 are the line numbers and rest is the command /program…… to execute above program/command you have to press ‘/’ then enter. in the sql editor you can do all the formatting/editing/file operations directly by selecting menu options provided by it.sql Or SQL> Run programname. edit and execute the sql command and programs.Ravi 9 . pass word and host string as given by the administrator. pl/sql commands/programs: 1). pass word and host string You have to enter user name. In two ways you can write your programs: a). directly at SQL prompt b). 2). do the following SQL> @ programname. Open your oracle application by the following navigation Start->all programs->oracle orahome. You will be asked for user name. Here editing the program is somewhat difficult. It will be different from one user to another user.(this is what I mentioned as a second method to type/enter the program). 3).empno.

author: string) Iss_rec(iss_no:integer. perform the following— a) Create the tables with the appropriate integrity constraints b) Insert around 10 records in each of the tables c) List all the bills for the current date with the customer names and item numbers d) List the total Bill details with the quantity sold. cust_id. qty_sold. amount Create a view which lists the daily sales date wise for the last one week 2 Database Schema for a Student Library scenario Student(Stud_no : integer. item_name: string. item_id. No 1 Name of the program Database Schema for a customer-sale scenario Customer(Cust id : integer. price. iss_date: date. Mem_no: integer. price: integer) Sale(bill_no: integer. Stud_name: string) Membership(Mem_no: integer. cust_id: integer. price of the item and the final amount e) List the details of the customer who have bought a product which has a price>200 f) Give a count of how many products have been bought by each customer g) Give a list of products bought by a customer having cust_id as 5 h) List the item details which are sold as of today i) Create a view which lists out the bill_no. book_name:string. bill_date. qty_sold: integer) For the above schema. book_no: integer) K.DBMS Lab Manual List of Lab Exercises Syllabus Programs (JNTU) S. bill_data: date.Ravi 10 . cust_name: string) Item(item_id: integer. item_id: integer. Stud_no: integer) Book(book_no: integer.

DBMS Lab Manual For the above schema. deductions: integer. perform the following— a) Create the tables with the appropriate integrity constraints b) Insert around 10 records in each of the tables c) List the employee details department wise d) List all the employee names who joined after particular date e) List the details of employees whose basic salary is between 10. dedeuctions. dept_name:string) paydetails(emp_id : integer. netsalary K. dept_id: integer. basic. pay_date: date) For the above schema.000 f) Give a count of how many employees are working in each department g) Give a names of the employees whose netsalary>10.000 and 20. DOJ: date) payroll(emp_id : integer. perform the following— a) Create the tables with the appropriate integrity constraints b) Insert around 10 records in each of the tables c) List all the student names with their membership numbers d) List all the issues for the current date with student and Book names e) List the details of students who borrowed book whose author is CJDATE f) Give a count of how many books have been bought by each student g) Give a list of books taken by student with stud_no as 5 h) List the book details which are issued as of today i) Create a view which lists out the iss_no. basic: integer. emp_name: string) department(dept_id: integer. book name j) Create a view which lists the daily issues-date wise for the last one week 3 Database Schema for a Employee-pay scenario employee(emp_id : integer. additions: integer. stud_name. department. iss _date.000 h) List the details for an employee_id=5 i) Create a view which lists out the emp_name.Ravi 11 .

DBMS Lab Manual j) Create a view which lists the emp_name and his netsalary 4 Database Schema for a Video Library scenario Customer(cust_no: integer.Ravi 12 . lab and machine numbers d) List the total number of lab allotments day wise e) Give a count of how many machines have been allocated K. iss_date. perform the following— a) Create the tables with the appropriate integrity constraints b) Insert around 10 records in each of the tables c) List all the machine allotments with the student names. descrip: string) Lab(mach_no: integer. cass_no: integer) For the above schema. iss_date: date. Language: String) Iss_rec(iss_no: integer. mach_no: integer. description: String) Allotment(Stud_no: Integer. class: string) Class(class: string. Lab_no: integer. stud_name: string. cust_name. perform the following— a) Create the tables with the appropriate integrity constraints b) Insert around 10 records in each of the tables c) List all the customer names with their membership numbers d) List all the issues for the current date with the customer names and cassette names e) List the details of the customer who has borrowed the cassette whose title is “ The Legend” f) Give a count of how many cassettes have been borrowed by each customer g) Give a list of book which has been taken by the student with mem_no as 5 h) List the cassettes issues for today i) Create a view which lists outs the iss_no. cass_name:string. dayof week: string) For the above schema. mem_no: integer.cust_name: string) Membership(Mem_no: integer. cust_no: integer) Cassette(cass_no:integer. cass_name j) Create a view which lists issues-date wise for the last one week 5 Database Schema for a student-Lab scenario Student(stud_no: integer.

Create a trigger before/after delete on employee table for each row/statement. Create a cursor. Write a program to find largest number from the given three numbers.Ravi 13 . Create a procedure to find reverse of a given number Create a procedure to update the salaries of all employees as per the given data Create a procedure to demonstrate IN. which displays all employee numbers and names from the EMP table. OUT and INOUT parameters Create a function to check whether given string is palindrome or not. Write a program to demonstrate %type and %rowtype attributes Write a program to demonstrate predefined exceptions Write a program to demonstrate user defined exceptions Create a cursor. while and for iterative control statement. Create a trigger before/after insert on employee table for each 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 K. Create a trigger before/after update on employee table for each row/statement. which update the salaries of all employees as per the given data.DBMS Lab Manual to the ‘CSIT’ class f) Give a machine allotment etails of the stud_no 5 with his personal and class details g) Count for how many machines have been allocatedin Lab_no 1 for the day of the week as “Monday” h) How many students class wise have allocated machines in the labs i) Create a view which lists out the stud_no. which displays names of employees having salary > 50000. Write a program to check whether the given number is Armstrong or not Write a program to generate all prime numbers below 100. mach_no. Simple programs using loop. stud_name. Write a program to demonstrate the GOTO statement. Create a cursor. dayofweek j) Create a view which lists the machine allotment details for “Thursday”. Create a function to find sum of salaries of all employees working in depart number 10. lab_no.

DBMS Lab Manual row/statement. Search.Ravi 14 . Delete. No 1 2 3 4 Name of the Program Create a form using Forms 6i to display Employee table data. Save and Update on the records Generate a report to calculate employee’s salaries department wise from employee table. K. 25 26 Additional Programs S. Create a Form to display employee details using SQL Create a Report to generate all employee annual salaries…. Create a Master/details relationship form which perform Add New. Create a Report to generate the details of employee table including sum and average salaries department wise.

DCL/DTL commands: . SQL is structure query language.To manipulate data of a database objects C). The Create Table Command: .DBMS Lab Manual Background Theory Oracle workgroup or server is the largest selling RDBMS product.s) 5. a name . Oracle corp has also incorporated a full-fledged java virtual machine into its database engine. varchar2(size) 3. Syntax: Create table <table <datatype><size>)). name> (<col1> <datatype>(<size>).SQL contains different data types those are 1.To retrieve the data from a database.it is estimated that the combined sales of both these oracle database product account for aroud 80% of the RDBMSsystems sold worldwide. char(size) 2. long 6. DML commands: .<col2> Ex: create table emp(empno number(4) primary key.PL/SQL a superset of ANSI SQL.oracle 8i and 9i also under stand SQLJ.Ravi 15 . DQL command: .To control the data of a database… DDL commands: 1.To create a database objects B). ename char(10)). number(p. date 4. Each column has minimum of three attributes.since both executable share the same memory space the JVM can communicate With the database engine with ease and has direct access to oracle tables and their data. raw/long raw Different types of commands in SQL: A). D). data type and size. The natural language of this RDBMS product is ANSI SQL.it defines each column of the table uniquely. DDL commands: . These products are constantly undergoing change and evolving. K.

Ex: alter table emp add(sal number(7. Ex: rename emp to emp1. 3.DBMS Lab Manual 2. Syntax: Truncate table <tablename>. Syntax: Alter table <tablename> modify(<col><newdatatype>(<newsize>)). Ex: trunc table emp1. a)add new columns Syntax: Alter table <tablename> col>datatype(size)).2)).Ravi 16 . Syntax: Alter table <tablename> drop column <col>. 6. Ex: alter table emp modify(ename varchar2(15)). truncating the tables. 5. Dropping a column from a table. Modifying existing columns. 4. Renaming the tables Syntax: Rename <oldtable> to <new table>. Ex: alter table emp drop column sal. Modifying the structure of tables.<new K. add(<new col><datatype(size).

DBMS Lab Manual 7. Syntax: insert into <tablename> (<col1>. a) remove all rows Syntax: delete from <tablename>. b) removal of a specified row/s Syntax: delete from <tablename> where <condition>. 9. DML commands: 8. a) updating all rows Syntax: Update <tablename> set <col>=<exp>.<col>=<exp>. Syntax: Drop table <tablename>.once a table is created the most natural thing to do is load this table with data to be manipulated later. Ex: drop table emp. Destroying tables.Ravi 17 . Inserting Data into Tables: . Syntax: Update <tablename> set where <condition>. <col>=<exp>.<col2>) values(<exp>.<exp>). Types of data constrains. Updating the contents of a table. Delete operations. 10. a) not null constraint at column level. Syntax: <col><datatype>(size)not null b) unique constraint Syntax: K. b) updating seleted records.<col>=<exp> 11.

<col2>).DBMS Lab Manual Unique constraint at column level.unique(<col1>. Syntax: <col><datatype>(size) check(<logical expression>) i) check constraint constraint at table level.<col2>). Syntax: Create table tablename(col=format. <col><datatype>(size)unique.col=format.col=format primary key(col1>. f) foreign key constraint at column level.<col>) h) check constraint check constraint constraint at column level. d) primary key constraint at column level Syntax: <col><datatype>(size)primary key. g) foreign key constraint at table level Syntax: foreign key(<col>[. e) primary key constraint at table level.<col>])references <tablename>[(<col>.Ravi 18 . Syntax: <col><datatype>(size>) references <tablename>[<col>]. Syntax: check(<logical expression>) K. c) unique constraint at table level: Syntax: Create table tablename(col=format.

<col2> <[sortorder]>. K. a) all rows and all columns Syntax: Select <col> to <col n> from tablename. DCL commands: Oracle provides extensive feature in order to safeguard information stored in its tables from unauthoraised viewing and damage. Viewing data in the tables: . Hence. 13.once data has been inserted into a table. the next most logical operation would be to view what has been inserted. a) Grant privileges using the GRANT statement The grant statement provides various types of access to database objects such as tables. c) selected columns and selected rows Syntax: select <col1>. Select * from tablename.while viewing data from a table. it is rare that all the data from table will be required each time.Ravi 19 . sql must give us a method of filtering out data that is not required data. b) selected rows and all columns: Syntax: select * from <tablename> where <condition>.<col2> from <tablename> where<condition>.views and sequences and so on. Syntax: Select * from <tablename> order by <col1>. Filtering table data: .DBMS Lab Manual DQL Commands: 12.The rights that allow the user of some or all oracle resources on the server are called privileges.<col2> from <tablename>. Sorting data in a table. 14. a) Selected columns and all rows: Syntax: select <col1>.

DBMS Lab Manual Syntax: GRANT <object privileges> ON <objectname> TO<username> [WITH GRANT OPTION]. Syntax: REVOKE<object privilege> ON FROM<user name>. K.Ravi 20 . b) Reoke permissions using the REVOKE statement: The REVOKE statement is used to deny the Grant given on an object.

cust_id: integer. cust_id. qty_sold. integer. amount j) Create a view which lists the daily sales date wise for the last one week K. qty_sold: integer) item_id: For the above schema. Database Schema for a customer-sale scenario Customer(Cust id : integer. price: integer) Sale(bill_no: integer. item_name: string. item_id. bill_date.DBMS Lab Manual Solutions for programs (JNTU Syllabus) 1. cust_name: string) Item(item_id: integer. price of the item and the final amount e) List the details of the customer who have bought a product which has a price>200 f) Give a count of how many products have been bought by each customer g) Give a list of products bought by a customer having cust_id as 5 h) List the item details which are sold as of today i) Create a view which lists out the bill_no. perform the following— a) Create the tables with the appropriate integrity constraints b) Insert around 10 records in each of the tables c) List all the bills for the current date with the customer names and item numbers d) List the total Bill details with the quantity sold.Ravi 21 . price. bill_data: date.

Ravi 22 . Output: Name Null? Type ----------------------------------------.'&custname'). SQL> select * from customer1. cust_name varchar2(15)). Output: Table created. item_name varchar2(15). Output: CUST_ID CUST_NAME ---------. SQL> desc customer1.-------.2)).DBMS Lab Manual Aim: Create the tables with the appropriate integrity constraints and Insert around 10 records in each of the tables HW/SW requirements: Processor RAM Hard Disk Software : : : : AMD Athelon ™ 1.67 GHz 256 MB 40 GB ORACLE SQL> create table customer1 (cust_id number(5) primary key.---------------CUST_ID NOT NULL NUMBER(5) CUST_NAME VARCHAR2(15) Valid Test Data b) SQL> insert into customer1 values(&custid.--------------100 ramu 101 kamal 102 raju 103 raju sundaram 104 lawrence SQL> create table item(item_id number(4) primary key. SQL> dsec item Output: Name Null? Type …………………………………………………………………………………………………… K.price number(6.

1450 04-JAN-06 100 2124 2 1451 04-JAN-06 101 2319 1 1452 04-JAN-06 103 4531 2 1453 04-JAN-06 102 2334 3 K.bill_date date. SQL>select * from sale. Output: ITEM_ID ITEM_NAME PRICE ……………………………………………………………………………………. Output: BILL_NO BILL_DATE CUST_ID ITEM_ID QTY_SOLD ………………………………………………………………………………………………………. &qty_sold).Ravi 23 .99 2319 duracell 45..65 2124 lays chips 20 4531 setwet 99. 2334 geera 6. item_id number(4) references item(item_id). &cust_id.&price).5 SQL>create table sale(bill_no number(5) primary key.. SQL>dsec sale Output: Name Null? Type ………………………………………………………………………………………. &item_id.25 4532 corn soup 34. SQL> select * from item. cust_id number(5) references customer(cust_id).DBMS Lab Manual Cust_id NOT NULL NUMBER(4) Item_name VARCHAR2(15) PRICE NUMBER(6.qty_sold number(4)). Out put: Table Created. BILL_NO NOT NULL NUMBER(4) BILL_DATE DATE CUST_ID NUMBER(5) ITEM_ID NUMBER(4) QTY_SOLD NUMBER(4) SQL>insert into Sale values(&bill_no. ’&bill_date’..2) SQL>insert into item values(&item_id.’&item_name’..

sale s where i.itemid.price*s.Ravi COUNT(ITEMID) --------------------2 24 .custid and s. s.custid=s. CUSTID ---------1 K. i.billdate=to_char(sysdate).(i.price. CUSTNAME ------------John ITEMID --------5001 BILLNO --------332 d) List the total Bill details with the quantity sold. price of the item and the final amount SQL> select i. CUSTID --------4 CUSTNAME -------------duffy f) Give a count of how many products have been bought by each customer SQL> select custid.custid. sale s.itemid=s.custname. item i where i.itemid.itemid=s. c.billno from customer c.custname from customer c.price>200 and c.qty) total from item I.qty.custid=s. sale s where c.custid and i. count(itemid) from sale group by custid.itemid. PRICE ------120 20 5 10 350 QTY ----2 3 2 1 4 TOTAL -------240 60 10 10 1400 e) List the details of the customer who have bought a product which has a price>200 SQL> select c. s.DBMS Lab Manual 1454 04-JAN-06 104 4532 3 c) List all the bills for the current date with the customer names and item numbers SQL> select c. item I.

cust_id. sale s where s.custid=s.itemid.itemid-s.billdate=to_char(sysdate).itemname from item i. qty_sold. SQL>select * from cust. c. iitemid.itemid and s.billdate. view created. bill_date.iemid=s. i. ITEMNAME -------------Pens h) List the item details which are sold as of today SQL> select i.sale s item I where c.itemid=s. ITEMID --------1234 ITEMNAME ------------pencil i) Create a view which lists out the bill_no.itemid. price.custid=5 and i.itemid). s.price.Ravi 25 .billno.custid and i.itemname from item I. amount SQL>create view cust as (select s.qty from customer c.custid. s. i. item_id. BILLNO BILLDATE CUSTID ITEMID PRICE QTY …………………………………………………………………………………………… 3432 12-JAN-06 3 3244 120 2 4424 20-FEB-06 1 3456 20 3 332 13-MAR-06 1 1234 5 2 2343 10-MAR 5 5001 10 1 1331 11-MAR-06 4 76776 350 4 j) Create a view which lists the daily sales date wise for the last one week K. sale s where i.DBMS Lab Manual 3 4 5 1 1 1 g) Give a list of products bought by a customer having cust_id as 5 SQL> select i. i.

Unauthorised access is restricted. 5. Difficult in accessing data. What is DBMS? It is a collection of programs that enables user to create and maintain a database. In other words it is general-purpose software that provides the users with the processes of defining. 4. Providing backup and recovery. 3.Ravi 26 . Enforcing integrity constraints. What is a Database system? The database and DBMS software together is called as Database system. Disadvantage in File Processing System? Data redundancy & inconsistency. Data isolation. constructing and manipulating the database for various applications. What is SQL? Ans: Structured Query Language 2. Concurrent access is not possible. K.       Advantages of DBMS? Redundancy is controlled. representing some aspect of real world and which is designed. What is database? A database is a logically coherent collection of data with some inherent meaning. Security Problems.      6. built and populated with data for a specific purpose.DBMS Lab Manual Viva-Voce: Q1. Data integrity. Providing multiple user interfaces.

Mem_no: integer. iss _date. Stud_name: string) Membership(Mem_no: integer. author: string) Iss_rec(iss_no:integer. stud_name. iss_date: date. perform the following— a) Create the tables with the appropriate integrity constraints b) Insert around 10 records in each of the tables c) List all the student names with their membership numbers d) List all the issues for the current date with student and Book names e) List the details of students who borrowed book whose author is CJDATE f) Give a count of how many books have been bought by each student g) Give a list of books taken by student with stud_no as 5 h) List the book details which are issued as of today i) Create a view which lists out the iss_no. book_no: integer) For the above schema. book name j) Create a view which lists the daily issues-date wise for the last one week K.Ravi 27 . book_name:string. Database Schema for a Student Library scenario Student(Stud_no : integer.DBMS Lab Manual 2. Stud_no: integer) Book(book_no: integer.

......DBMS Lab Manual AIM: Create the tables with the appropriate integrity constraints Insert around 10 records in each of the tables HW/SW requirements: Processor RAM Hard Disk : : : AMD Athelon ™ 1.....stud_name varchar2(15))....stud_no number(5) references student(stud)no)). Name Null? Type ………………………………………………………………………………………...... SQL>select * from student.......................’&stud_name’).... 508 513 518 524 534 HARISH BALAJI RAKESH PAVAN JOYCE SQL>create table membership(mem_no number(5) primary key..Ravi 28 . SQL>dsec membership...67 GHz 256 MB 40 GB Software : Oracle SQL>create table student(stud_no number(5) primary key. STUD_NO STUD_NAME .. STUD_NO NOT NULL NUMBER(5) STUD_NAME VARCAHR2(15) Valid Test Data: SQL>insert into student values(&stud_no. SQL>desc student........... Name Null? Type ……………………………………………………………………………………………………........ MEM_NO NOT NULL NUMBER(5) STUD_NO NUMBER(5) K.....

BOOK_NO BOOK_NAME AUTHOR ………………………………………………………………………………………………. BOOK_NO NOT NULL NUMBER(5) BOOK_NAME VARCHAR2(20) AUTHOR VARCHAR2(20) SQL>insert into book values(&book_no.510) * Errors Observed: ERROR at line 1: ORA-02291:integrity constraint(HARISH..DBMS Lab Manual SQL>insert into membership values(&mem_no.&stud_no) new 1:insert into membership values(5440. Name Null? Type ………………………………………………………………………………………..&stud_no).. 9123 DBMS Rama Krishna 2342 JAVA Robett wilkins 4523 Fearless tales Alfred 8723 my ambition Harish 7821 Harry Potter JK Rowling K.book_name varchar2(20). 5440 513 5441 508 5442 518 5443 534 5444 524 SQL>create table book(book_no number(5) primary key.author varchar2(2)).SYS_C002724)violated-primary key not found SQL>select * from membership.’&book_name’.510) insert into membership values(5440.Ravi 29 . SQL>desc book. SQL>select * from book. MEM_NO STUD_NO ……………………………………………………………………….’&author’). Enter value for mem_no:5440 Enter value for stud_no:510 old 1:insert into membership values(&mem_no.

memno=m.studno=s.studno=s. student s. Name Null? Type ……………………………………………………………………………………………………… ISS_NO NOT NULL NUMBER ISS_DATE DATE MEM_NO NUMBER(5) BOOK_NO NUMBER(5) SQL>select * from iss_rec.studno and i.DBMS Lab Manual SQL>create table lss_rec(iss_no number primary key. STUDNAME MEMNO --------------------abhijeet 1001 arun 1002 arvind 1003 ashish 1004 ashwin 1005 d) List all the issues for the current date with student and Book names SQL> select i.studname.bookname from iss_rec I. SQL>desc iss_rec.memno from student s. ISSNO ------K.mem_no number(5) references membership(mem_no). book b 2 where i.issno. s.studname. ISS_NO ISS_DATE MEM_NO BOOK_NO ………………………………………………………………………………………………… 43 05-JAN-06 5443 4523 81 28-DEC-05 5441 8723 22 08-DEC-05 5440 7821 53 07-JAN-06 5442 9123 35 06-JAN-06 5444 2342 c) List all the student names with their membership numbers SQL> select s. m.iss_date date.book_no number(5) references book(book_no)).memno and m. membership m where m.issdate=to_char(sysdate). membership m.Ravi STUDNAME BOOKNAME -------------------------30 .studno. b.

K.bookno=i.studno and b.membership m.Ravi 31 . STUDNO ---------505 STUDNAME ------------ashwin f) Give a count of how many books have been bought by each student SQL> select s. STUDNO ---------501 502 503 504 505 COUNT(I. count(i.BOOKNO) ----------------------5 5 5 5 5 g) Give a list of books taken by student with stud_no as 5 SQL> select bookname from book where bookno in (select bookno from iss_rec where 2 memno in(select memno from membership where 3 studno in(select studno from student where studno=5))).bookno group by s.studno. BOOKNAME ------------NT h) List the book details which are issued as of today SQL> delete from book where bookno in(select bookno from iss_rec where issdate=to_char(sysdate)).studno=m.bookno) from student s. book b.DBMS Lab Manual 13 arvind P&S e) List the details of students who borrowed book whose author is CJDATE SQL> select * from student where studno in(select studno from membership where memno in 2 (select memno from iss_rec where bookno in(select bookno from book where author=’CJDATE’))). 2 iss_rec I where s.studno.

Intension - K.DBMS Lab Manual delete from book where bookno in (select bookno from iss_rec where issdate=to_char(sysdate)) Errors Observed: ERROR at line 1: ORA-02292: integrity constraint (SCOTT. This is time dependent. describes what data are stored in database and what relationship among those data.  View level: The highest level of abstraction describes only part of entire database.Ravi 32 . 2.SYS_C00840) violated – child record found i) Create a view which lists out the iss_no.  Entity Integrity: States that “Primary key cannot have NULL value”  Referential Integrity: States that “Foreign Key can be either a NULL value or should be Primary Key value of other relation. stud_name. What is extension and intension? Extension It is the number of tuples present in a table at any instance.  Logical level: The next higher level of abstraction. Define the "integrity rules" There are two Integrity rules. iss _date. Describe the three levels of data abstraction? The are three levels of abstraction:  Physical level: The lowest level of abstraction describes how data are stored. book name j) Create a view which lists the daily issues-date wise for the last one week Viva-Vice: 1. 3.

DBMS Lab Manual It is a constant value that gives the name. structure of table and the constraints laid on it. Hence accounts for logical data independence. Two types of Data Independence:  Physical Data Independence: Modification in physical level should not affect the logical level. How is the data structure of System R different from the relational structure? Unlike Relational systems in System R  Domains are not supported  Enforcement of candidate key uniqueness is optional  Enforcement of entity integrity is optional  Referential integrity is not enforced 6. with performance at least comparable to that of existing system. What is a view? How it is related to data independence? A view may be thought of as a virtual table. 5. that is. K. a table that does not really exist in its own right but is instead derived from one or more underlying base table. What is Data Independence? Data independence means that “the application is independent of the storage structure and access strategy of data”. It is a prototype and its purpose was to demonstrate that it is possible to build a Relational System that can be used in a real life environment to solve real life problems. there is no stored file that direct represents the view instead a definition of view is stored in data dictionary. 4.Ravi 33 . The ability to modify the schema definition in one level should not affect the schema definition in the next higher level. Growth and restructuring of base tables is not reflected in views.  Logical Data Independence: Modification in logical level should affect the view level. Its two subsystems are  Research Storage  System Relational Data System. Thus the view can insulate users from the effects of restructuring and growth in the database. NOTE: Logical Data Independence is more difficult to achieve 7. In other words. What is System R? What are its two major subsystems? System R was designed and developed over a period of 1974-79 at IBM San Jose Research Center. In other words.

DBMS Lab Manual 3. department. pay_date: date) For the above schema. dept_name:string) paydetails(emp_id : integer. basic: integer.000 f) Give a count of how many employees are working in each department g) Give a names of the employees whose netsalary>10. additions: integer. DOJ: date) payroll(emp_id : integer.000 and 20.000 h) List the details for an employee_id=5 i) Create a view which lists out the emp_name. dedeuctions. perform the following— a) Create the tables with the appropriate integrity constraints b) Insert around 10 records in each of the tables c) List the employee details department wise d) List all the employee names who joined after particular date e) List the details of employees whose basic salary is between 10.Ravi 34 . deductions: integer. Database Schema for a Employee-pay scenario employee(emp_id : integer. emp_name: string) department(dept_id: integer. basic. netsalary j) Create a view which lists the emp_name and his netsalary K. dept_id: integer.

Name Null? Type ………………………………………………………………………………………. EMP_ID NOT NULL NUMBER(5) EMP_NAME VARCHAR2(25) Valid Test Data: SQL>insert into employee values(&emp_id. DEPT_ID NOT NULL NUMBER(5) DEPT_NAME VARCHAR2(20) SQL>insert into department values(&dept_id..dept_name varchar2(20)). Name Null? Type ……………………………………………………………………………………….’&emp_name’). K. SQL>desc employee.DBMS Lab Manual AIM: Create the tables with the appropriate integrity constraints Insert around 10 records in each of the tables HW/SW requirements: Processor RAM Hard Disk : : : AMD Athelon ™ 1. EMP_ID EMP_NAME …………………………………………………………. SQL>select * from employee. 10 Robert 21 Coulthard 30 Fernando Alonso 39 Kartikeyan 87 Kimmi SQL>create table department(dept_id number(5) primary key.’&dept_name’).emp_name varchar2(25))..Ravi 35 .67 GHz 256 MB 40 GB Software : Oracle Create table employee(emp_id number(5) primary key. SQL>desc department.

SQL>desc paydetails.2).09 71.8 24-SEP-04 SQL>create table payroll(emp_id number(5)references employee(emp_id).DBMS Lab Manual SQL>select * from department.additions number(5.9 01-JAN-06 30 102 6500.2) ADDITIONS NUMBER(5.5 30...&dept_id.54 15 06-JUL-97 39 103 9700.basic number(7.Ravi Null? Type 36 . SQL>select * from paydeatils. &basic. DEPT_ID DEPT_NAME …………………………………………………………………………….&additions.2). Name Null? Type ………………………………………………………………………………………. 10 101 25023.12 43.2) DEDUCTIONS NUMBER(5. 100 sales 101 accounts 102 administration 103 production 104 supervisor SQL>create table paydetails(emp_id number(5) references employee(emp_id).98 40.doj date). EMP_ID NUMBER(5) DEPT_ID NUMBER(5) BASIC NUMBER(7.09 08-AUG-03 87 104 15000 97..2) DOJ DATE Different Data Sets: SQL>insert into paydeatils values(&emp_id.pay_date date).78 65.&deductions. Name K.29 23.deductions number(5.45 32. SQL>desc payroll. EMP_ID DEPT_ID BASIC DEDUCTIONS ADDITIONS DOJ ………………………………………………………………………………………………………………….dept_id number(5) reerences department(dept_id).66 154.2).&doj).23 08-JAN-93 21 100 10500.

doj>=’05-mar-06’. EMP_ID PAY_DATE ………………………………………………………….empname from employee e.000 and 20.empname from employee where salary between 10000 and 20000.’&date’).. 10 31-JAN-06 21 03-FEB-06 30 15-JAN-06 39 27-JAN-06 87 04-FEB-06 c) List the employee details department wise SQL>select empid.Ravi EMPNAME 37 .000 sqL> Select empid.paydet p where e. EMPNAME ………………… AVINASH NITIN PHALGUN e) List the details of employees whose basic salary is between 10. EMPID K.empid and p.DBMS Lab Manual ………………………………………………………………………………………. EMPID DEPTID ………………………… 401 500 402 200 403 600 404 400 405 1200 d) List all the employee names who joined after particular date SQL>select e.empid=p.deptid from paydet. SQL>select * from payroll. EMP_ID NUMBER(5) PAY_DATE DATE SQL>insert into payroll values(&emp_id.

deptid from paydet group by deptid. 402 AKHILA 403 aaaaaaaa EMPID EMPNAME …………………………….Ravi 38 . EMPNAME ……………… AVINASH AKHILA HARISH NITIN PHALGUN h) List the details for an employee_id=5 SQL> select * from employee where empid=5.DBMS Lab Manual ……………………………. EMPID EMPNAME -----------------------------------------5 Coulthard K. COUNT (EMPID) DEPTID ……………………………………………………… 1 200 1 400 1 500 1 600 1 1200 g) Give a names of the employees whose netsalary>10.000 SQL> select empname from employee where empid in(select empid from paydet where basic-deduction>10000). AKHILA f) Give a count of how many employees are working in each department SQL>select count(empid).

DBMS Lab Manual i) Create a view which lists out the emp_name, department, basic, dedeuctions, netsalary Create a view which lists the emp_name and his netsalary

j)

Viva-Vice: 13. What is Data Model? A collection of conceptual tools for describing data, data relationships data semantics and constraints. 14. What is E-R model? This data model is based on real world that consists of basic objects called entities and of relationship among these objects. Entities are described in a database by a set of attributes. 15. What is Object Oriented model? This model is based on collection of objects. An object contains values stored in instance variables with in the object. An object also contains bodies of code that operate on the object. These bodies of code are called methods. Objects that contain same types of values and the same methods are grouped together into classes. 16. 17. 18. What is an Entity? It is a 'thing' in the real world with an independent existence. What is an Entity type? It is a collection (set) of entities that have same attributes. What is an Entity set? It is a collection of all entities of particular entity type in the database.

K.Ravi

39

DBMS Lab Manual

4. Database Schema for a Video Library scenario
Customer(cust_no: integer,cust_name: string) Membership(Mem_no: integer, cust_no: integer) Cassette(cass_no:integer, cass_name:string, Language: String) Iss_rec(iss_no: integer, iss_date: date, mem_no: integer, cass_no: integer) For the above schema, perform the following— a) Create the tables with the appropriate integrity constraints b) Insert around 10 records in each of the tables c) List all the customer names with their membership numbers d) List all the issues for the current date with the customer names and cassette names e) List the details of the customer who has borrowed the cassette whose title is “ The Legend” f) Give a count of how many cassettes have been borrowed by each customer g) Give a list of book which has been taken by the student with mem_no as 5 h) List the cassettes issues for today i) Create a view which lists outs the iss_no, iss_date, cust_name, cass_name j) Create a view which lists issues-date wise for the last one week

K.Ravi

40

DBMS Lab Manual

AIM: Create the tables with the appropriate integrity constraints
Insert around 10 records in each of the tables

HW/SW requirements:
Processor RAM Hard Disk : : : AMD Athelon ™ 1.67 GHz 256 MB 40 GB

Software

:

Oracle

SQL>create table customer(cust_no number(5) primary key,cust_name varchar2(20)); SQL>desc customer; Name Null? Type …………………………………………………………………………………………………………….. CUST_NO NOT NULL NUMBER(5) CUST_NAME VARCHAR2(20) Valid Test Data: SQL>insert into customer values(&cust_no,’&cust_name’); SQL>select * from customer; CUST_NO CUST_NAME ………………………………………………………………. 50 scott 51 pandey 52 varshney 53 naidu 54 bhimbra SQL>create table membership(mem_no number(5) primary key,cust_no number(5) references customer(cust_no)); SQL>dsec membership; Name Null? Type ………………………………………………………………………………………………………... MEM_NO NOT NULL NUMBER(5) CUST_NO NUMBER(5)

K.Ravi

41

iss_date date. SQL>desc issu_rec. SQL>desc cassette. MEM_NO CUST_NO ………………………………………………… 920 50 981 51 897 52 820 53 928 54 SQL>crea te table cassette(cass_no number(5) primary key.mem_no number(5)references memship(mem_no). CASS_NO NOT NULL NUMBER(5) CASS_NAME VARCHAR2(15) LANGUAGE VARCHAR2(15) SQL>insert into cassette values(&cass_no.’&cass_name’. Name Null? Type ……………………………………………………………………………………………………….Ravi 42 .’&language’).DBMS Lab Manual SQL>insert into memship values(&mem_no.. Name Null? Type ……………………………………………………………………………………….&cust_no). Cass_name varchar2(15).. SQL>select * from cassette.cass_no number(5) references cassette(cass_no)). CASS_NO CASS_NAME LANGUAGE ……………………………………………………………………………………… 1 tagore telugu 2 the lion king English 3 anniyan tamil 4 indra telugu 5 lord of rings English SQL>create table issu_rec(iss_no number(5) primary key. ISS_NO NOT NULL NUMBER(5) ISS_DATE DATE MEM_NO NUMBER(5) K.language varchar2(15)).. SQL>select * from memship.

custno=m.custname.cc. NIKHIL 51 VIVEK 52 SHRAVAN 58 VAMSI 57 SHIVA 56 d) List all the issues for the current date with the customer names and cassette names SQL>select i.Ravi 43 NUMBER(5) .c. e) List the details of the customer who has borrowed the cassette whose title is “ The Legend” f) Give a count of how many cassettes have been borrowed by each customer g) Give a list of book which has been taken by the student with mem_no as 5 h) List the cassettes issues for today K..cassno and i.custno=m.issrec1 I where i.cassno=cc.custname.cassette cc.memno. ISS_NO ISS_DATE MEM_NO CASS_NO …………………………………………………………………………………… 22 07-JAN-06 920 1 23 10-JAN-00 981 2 26 10-JAN-06 897 5 3 01-JAN-06 820 4 34 31-DEC-05 928 3 c) List all the customer names with their membership numbers SQL>select c.issdate=to_char(sysdate) and c.memno=m.custno.issno. CUSTNAME MEMNO ………………..m.membership1 m where c. ……………….membership1 m.custno and i.cassettename from customer1 c.DBMS Lab Manual CASS_NO SQL>select * from issu_rec. OutPut: no rows selected.memno from customer1 c.

A relation is defined as a set of tuples. 22. Each tuple is an ordered list of n-values t=(v1. A2. cust_name. An) is made up of the relation name R and the list of attributes Ai that it contains. 23. What is an Extension of entity type? The collections of entities of a particular entity type are grouped together into an entity set.. then it is said to be Weak Entity set. 21..v2. t3.. tn). What is an attribute? It is a particular property. What is Weak Entity set? An entity set may not have sufficient attributes to form a primary key. Let r be the relation which contains set tuples (t1.DBMS Lab Manual i) Create a view which lists outs the iss_no.. . vn). . What is Relationship set? The collection (or set) of similar relationships. 20. and its primary key compromises of its partial key and primary key of its parent entity. What is a Relation Schema and a Relation? A relation Schema denoted by R(A1. 25. What is Relationship? It is an association among two or more entities. K..Ravi 44 . cass_name j) Create a view which lists issues-date wise for the last one week Viva-Vice: 19. t2. iss_date. which describes the entity. What is degree of a Relation? It is the number of attribute of its relation schema.. 24. ….

Lab_no: integer. lab_no. class: string) Class(class: string. descrip: string) Lab(mach_no: integer. mach_no.DBMS Lab Manual 5.Ravi 45 . mach_no: integer. description: String) Allotment(Stud_no: Integer. lab and machine numbers d) List the total number of lab allotments day wise e) Give a count of how many machines have been allocated to the ‘CSIT’ class f) Give a machine allotment etails of the stud_no 5 with his personal and class details g) Count for how many machines have been allocatedin Lab_no 1 for the day of the week as “Monday” h) How many students class wise have allocated machines in the labs i) Create a view which lists out the stud_no. stud_name: string. stud_name. dayof week: string) For the above schema.Database Schema for a student-Lab scenario Student(stud_no: integer. perform the following— a) Create the tables with the appropriate integrity constraints b) Insert around 10 records in each of the tables c) List all the machine allotments with the student names. dayofweek j) Create a view which lists the machine allotment details for “Thursday” K.

67 GHz 256 MB 40 GB Software : Oracle SQL>create table stu(stud_no number(5) primary key. descript varchar2(10)).DBMS Lab Manual AIM: Create the tables with the appropriate integrity constraints Insert around 10 records in each of the tables HW/SW requirements: Processor RAM Hard Disk : : : AMD Athelon ™ 1. description varchar2(20)). SQL> Describe class. lab_no number(5). K. SQL> select * from stu. Name CLASS DESCRIPT null type VARCHAR2(10) VARCHAR2(20) SQL> create table lab(match_no number(5).stud_nam varchar2(20).class varchar2(20)). SQL> desc stu.’&class’). STUD_NO 39 34 18 8 24 STUD_NAM LEON VIKAS MATHEW HANSEN ALEXIS CLASS CSE CSIT ECE MECH EEE null? NOT NULL Type NUMBER(5) VARCHAR2(20) VARCHAR2(20) SQL> Create table class (class varchar2(20). Name STUD_NO STUD_NAM CLASS Valid Data Sets: SQL> insert into stu values(&stud_no.Ravi 46 .’&stud_nam’.

Ravi 47 . SQL> desc allotment.’&description’). Name MACH_NO LAB_NO DESCRIPTION null NOT NULL type NUMBER(5) NUMBER(5) VARCHAR2(20) SQL> insert into lab values(&mach_no.&lab_no. STUD_NO --------------39 34 18 8 24 MACH_NO -----------23 87 78 12 12 DOWEEK -----------sat mon tue wed thu K. Name -------------STUD_NO MACH_NO DOWEEK Null? ------Type --------NUMBER(5) NUMBER(5) VARCHAR2(20) SQL>select * from allotment. SQL> select * from lab. MATCH_NO LAB_NO DESCRIPTION -----------------------------------------23 7 physics 78 2 chemistry 87 1 edc 12 10 cds 8 3 java lab SQL> create table allotment(stud_no number(5) references stu(stud_no).DBMS Lab Manual SQL> desc lab. Doweek varchar2(20)). match_no number(5) references lab(mach_no).

Ravi 48 . COUNT (MACHNO) …………………….machno from student1 s.machno=l. lab and machine numbers SQL>select s.allotment a where a.studno and a..studname. ABHIJEET 1 KALYAN 22 ASHWIN 3 ARKA 4 ARVIND 5 d) List the total number of lab allotments day wise SQL>select l.s.studno=s.a.day from lab l.descrip.studno.class from allotment a.machno.studno=s. STUDNAME MACHNO ……………………………………….allotment a where a.DBMS Lab Manual c) List all the machine allotments with the student names.l.studname.lab l.student1 s where a. K. MACHNO DESCRIP DAY …………………………………………………………………… 1 UNIX MONDAY 22 UNIX TUESDAY 3 XP WEDNESDAY 4 WINDOWS THRUSDAY 5 ME FRIDAY e) Give a count of how many machines have been allocated to the ‘CSIT’ class SQL>select count(machno)from allotment where studno in(select studno from student1 where class=’CSIT’). 1 f) Give a machine allotment etails of the stud_no 5 with his personal and class details SQL>select a.studno.a.machno=l.machno.l.studno=503..machno and a.s.machno.

dayofweek j) Create a view which lists the machine allotment details for “Thursday” Viva-Vice: 26.Ravi 49 . lab_no. 25. What is Relationship type? Relationship type defines a set of associations or a relationship set among a given set of entity types. 27. What is degree of Relationship type? It is the number of entity type participating. stud_name. allocated students in the lab CLASS …………………………………………………………………………… 2 CSE 1 ECE 1 EEE 1 IT i) Create a view which lists out the stud_no. What is DDL (Data Definition Language)? A data base schema is specifies by a set of definitions expressed by a special language called DDL. mach_no.class from student1 where studno in(select studno from allotment) group by class. K.DBMS Lab Manual STUDNO MACHNO STUDNAME CLASS ……………………………………………………………………………………………………… 503 5 ARVIND CSE g) Count for how many machines have been allocatedin Lab_no 1 for the day of the week as “Monday” h) How many students class wise have allocated machines in the labs SQL>select count(studno) “allocated students in the labs”.

28.  Procedural DML or Low level: DML requires a user to specify what data are needed and how to get those data. 29. What is VDL (View Definition Language)? It specifies user views and their mappings to the conceptual schema. K. 27. What is SDL (Storage Definition Language)? This language is to specify the internal schema. 31.Ravi 50 .DBMS Lab Manual 26.Definition Language? The storage structures and access methods used by database system are specified by a set of definition in a special type of DDL called data storage-definition language. What is DML (Data Manipulation Language)? This language that enable user to access or manipulate data as organised by appropriate data model.  Non-Procedural DML or High level: DML requires a user to specify what data are needed without specifying how to get those data. What is DML Compiler? It translates DML statements in a query language into low-level instruction that the query evaluation engine can understand. This language may specify the mapping between two schemas. What is Data Storage .

Step 3: Compare variable A with B and A with C Step 4: If the value stored in variable A is big. C number. HW/SW requirements: Processor RAM Hard Disk : : : AMD Athelon ™ 1. Step 2: Store the valid data. it displays “B is Big”. B:=&b.Ravi 51 . Begin A:=&a. Write a program to find largest number from the given three numbers.DBMS Lab Manual 6).67 GHz 256 MB 40 GB Software Algorithm: : Oracle. PlSQL Step 1: Declare the variable A. and C. (IF conditional statement should be used) Step 5: Compare variable B with C Step 6: If the value stored in variable B is big. B number. C:=&c. Step 7: other wise it displays “C is Big” Declare A number. it displays “A is Big”. If a > b && a> c then K. B. Aim: To find largest number from the given three numbers.

End if. End. Valid Data Sets: Enter the value of a: 1 Enter the value of b: 2 Enter the value of c: 3 OUTPUT: C is big Invalid Data sets : Enter the value of a: y Enter the value of b: x Enter the value of c: a Output: Invalid data types.put_line(‘ A is big ‘).Ravi 52 . Else Dbms_output. Viva-Vice: K.put_line(‘ B is big ‘).put_line(‘ C is big ‘).DBMS Lab Manual Dbms_output. End if. Else If( b>c && b> a ) then Dbms_output.

Ravi 53 . QUEL. What is Query evaluation engine? It executes low-level instruction generated by compiler. 37. Codd. K.DBMS Lab Manual 31. 33.F. What is Relational Calculus? It is an applied predicate calculus specifically tailored for relational databases proposed by E. What is Relational Algebra? It is procedural query language.g. E. 36. 34. This retrieve of a record is said to be Setat-a-time or Set-oriented. It consists of a set of operations that take one or two relations as input and produce a new relation. What is DDL Interpreter? It interprets DDL statements and record them in tables containing metadata. What is Record-at-a-time? The Low level or Procedural DML can specify and retrieve each record from a set of records. 35. of languages based on it are DSL ALPHA. What is Set-at-a-time or Set-oriented? The High level or Non-procedural DML can specify and retrieve many records in a single DML statement. What is Pl-SQL ? Procedural Language Structured Query Language 32. This retrieve of a record is said to be Record-at-atime.

the loop will be terminated. a) To generate first 10 natural numbers using loop. while and for. PlSQL Declare the variable I. AIM: To generate first 10 natural numbers using loop. and repeat the loop If condition exceeds the given value 10. I:=I+1. Store the valid data 1 in I.67 GHz 256 MB 40 GB Software Algorithm: Step Step Step Step Step Step Step 1: 2: 3: 4: 5: 6: 7: : Oracle. while and for iterative control statement. Increment the value of I by 1 value. Use LOOP statement Display the first value. Begin I:=1. Loop Dbms_output. HW/SW requirements: Processor RAM Hard Disk : : : AMD Athelon ™ 1. while and for. /* using loop statement */ Declare I number. K. check the value up to 10 no.DBMS Lab Manual 7). Simple programs using loop.Ravi 54 .put_line(I).

End. /* using while */ Declare I number. End loop. End.put_line(I). I:=I+1. Store the valid data 1 in I. Algorithm: for WHILE loop Step Step Step Step Step Step Step 1: 2: 3: 4: 5: 6: 7: Declare the variable I.DBMS Lab Manual Exit when I>10.Ravi 55 . Use WHILE statement Check the value of I with value 10. While (I<=10) loop Dbms_output. Begin I:=1. if the value of I reached to 10 the loop will be terminated otherwise display value of I increment the next value of I using I=I+1. End loop. K.

10 loop Dbms_output.put_line(I).DBMS Lab Manual Algorithm: Step 1: Declare the variable I. End. /* using for loop*/ Begin For I in 1. Valid Test Data: OUTPUT 1 2 3 4 5 6 7 8 9 10 K. I. Step 2: Store the value 1 in var.Ravi 56 . and repeat the loop Step 7: if the loop exceeds the value 10 then the loop will be terminated. Step 6: check the value up to 10 no. Step 3: Use For… LOOP statement Step 4: Display the first value of I. Step 5: Increment the value of I by 1 value. End loop..

variables that range over the underlying domains instead of over relation. specifies the following constraint on any relation r of R: if two tuples t1 and t2 exist in r such that t1[X] = t2[X] then t3 and t4 should also exist in r with the following properties  t3[x] = t4[X] = t1[X] = t2[X]  t3[Y] = t1[Y] and t4[Y] = t2[Y]  t3[Z] = t2[Z] and t4[Z] = t1[Z] where [Z = (R-(X U Y)) ] K. E.Ravi 57 .e. deletion and update anomalies. What is Multivalued dependency? Multivalued dependency denoted by X Y specified on relation schema R.g.DBMS Lab Manual Viva-Vice: 38. variable whose only permitted values are tuples of that relation. What is Functional Dependency? A Functional dependency is denoted by X Y between two sets of attributes X and Y that are subsets of R specifies a constraint on the possible tuple that can form a relation state r of R. where X and Y are both subsets of R. When is a functional dependency F said to be minimal?  Every dependency in F has a single attribute for its right hand side. 41.g. 42. This means the value of X component of a tuple uniquely determines the value of component Y.. How does Tuple-oriented relational calculus differ from domainoriented relational calculus The tuple-oriented calculus uses a tuple variables i.e. DEDUCE.. E. 40. QUEL The domain-oriented calculus has domain variables i. ILL.  We cannot replace any dependency X A in F with a dependency Y A where Y is a proper subset of X and still have a set of dependency that is equivalent to F. The constraint is for any two tuples t1 and t2 in r if t1[X] = t2[X] then they have t1[Y] = t2[Y].  We cannot remove any dependency from F and still have set of dependency that is equivalent to F. 39. What is normalization? It is a process of analysing the given relation schemas based on their Functional Dependencies (FDs) and primary key to achieve the properties  Minimizing redundancy  Minimizing insertion.

DBMS Lab Manual 43. What is Lossless join property? It guarantees that the spurious tuple generation does not occur with respect to relation schemas after decomposition. K.Ravi 58 .

DBMS Lab Manual 8. Step 2: Store the value in var. (D=n%10). Step 8: Check whether the stored value and calculated values are same Step 9: if both the values are same.67 GHz 256 MB 40 GB Software Algorithm: : Oracle. which is not equal to 0. 5. Step 6: The coefficient will be calculated using FLOOR function. S. S number. Step 5: the reminder will be multiply 3 times and store it in Var. Begin N:=&n. N and var. then display “The given number is Armstrong” Step 10: Otherwise display “it is not Armstrong” and terminate the loop. Pl-SQL Step 1: Declare the variable N. 4. S:=0. While(n!=0) K.Ravi 59 . Step 3: check for the value of N. S. whether given number is AIM: to check whether given number is Armstrong or not. D. Declare N number. N. Step 4: divide value stored in N by 10 and store it var. D and DUP. And store it in var.. Program to check Armstrong or not. DUP. D number. Step 7: repeat the Steps 3. HW/SW requirements: Processor RAM Hard Disk : : : AMD Athelon ™ 1. and 6 till loop will be terminated.

S:=s+(D*D*D). End if.Ravi 60 . 45.put_line(‘number is not armstrong’). 46. indivisible) values. A functional dependency X Y is full functional dependency if removal of any attribute A from X means that the dependency does not hold any more. Else DBMS_output. End loop. What is Fully Functional dependency? It is based on concept of full functional dependency. Test Valid Data Set: Enter value of n 153 OUTPUT: number is Armstrong. What is 1 NF (Normal Form)? The domain of attribute must include only atomic (simple. 47. End. If (DUP=S) then DBMS_output. Viva-Vice: 44.DBMS Lab Manual Loop D=n%10. N:=floor(n/10). What is 3NF? K. What is 2NF? A relation schema R is in 2NF if it is in 1NF and every non-prime attribute A in R is fully functionally dependent on primary key.put_line(‘number is armstrong’).

49. X must be a candidate key. What is 4NF? A relation schema R is said to be in 4NF if for every Multivalued dependency Y that holds over R.  A is a prime attribute of R. In other words. if every non prime attribute is non-transitively dependent on primary key. one of following is true  X is subset or equal to (or) XY = R.  X is a super key.DBMS Lab Manual A relation schema R is in 3NF if it is in 2NF and for every FD X A either of the following is true  X is a Super-key of R. X K. What is BCNF (Boyce-Codd Normal Form)? A relation schema R is in BCNF if it is in 3NF and satisfies an additional constraint that for every FD X A.Ravi 61 . 48.

DBMS Lab Manual 9. C number. J:=1. K. End loop. Begin While(i<=100) Loop C:=0. AIM: to generate all prime numbers below 100. Write a program to generate all prime numbers below 100. End if.67 GHz 256 MB 40 GB Software Declare I number.Ravi 62 . J:=j+1. While(j<=i) Loop : Oracle. J number. PlSQL If(floor(i%j)=0) then C:= C+1. HW/SW requirements: Processor RAM Hard Disk : : : AMD Athelon ™ 1.

End if. . End. artificial.. K.put_line(i).. 99 Viva-Vice: 50.  The join dependency is implied by the set of FD.Ravi 63 . It is sometime called as Discriminator. Valid Test Data OUTPUT: 2 3 5 7 11 .. one the following is true  Ri = R for some i.DBMS Lab Manual If(c=2) then Dbms_output. compound and natural key? Partial Key: It is a set of attributes that can uniquely identify weak entities and that are related to same owner entity.. 52. R2. Rn} that holds R. . 51. Endloop. What is Domain-Key Normal Form? A relation is said to be in DKNF if all constraints and dependencies that should hold on the the constraint can be enforced by simply enforcing the domain constraint and key constraint on the relation. over R in which the left side is key of R. What are partial. What is 5NF? A Relation schema R is said to be 5NF if for every join dependency {R1. alternate.

What is indexing and what are the different kinds of indexing? Indexing is a technique for determining how quickly specific data can be found. Then this is known as developing an artificial key. Artificial Key: If no obvious key. Natural Key: When one of the data elements stored within a construct is utilized as the primary key. 53. Compound Key: If no single data element uniquely identifies occurrences within a construct. then the last resort is to simply create a key.DBMS Lab Manual Alternate Key: All Candidate Keys excluding the Primary Key are known as Alternate Keys. Types:  Binary search style indexing  B-Tree indexing  Inverted list indexing  Memory resident table  Table indexing K. either stand alone or compound is available.Ravi 64 . by assigning a unique number to each record or occurrence. then it is called the natural key. then combining multiple elements to create a unique identifier for the construct is known as creating a compound key.

program to demonstrate the GOTO AIM: to demonstrate the GOTO statement HW/SW requirements: Processor RAM Hard Disk : : : AMD Athelon ™ 1.put_line( ‘ I is negative’). End.67 GHz 256 MB 40 GB Software : Oracle. End if. If(i>=0) then GOTO here.put_line( ‘ I is positive’). PlSQL Declare I number. Valid Test Data OUTPUT: I is positive K. Else Dbms_output.Ravi 65 . Begin I:=1. <<here>> Dbms_output.DBMS Lab Manual 10. Write a statement.

R2. 58. the DBMS can reduce the amount of work to be done during restart in the event of subsequent crashes. Rn} is said to hold over a relation R if R1. R2. information about every relation and index that it contains. It is also called data dictionary. 59... . What is meant by query optimization? The phase that identifies an efficient execution plan for evaluating a query that has the least estimated cost is referred to as query optimization. the delay in propagating local information might cause the deadlock detection algorithms to identify deadlocks that do not really exist. What is durability in DBMS? Once the DBMS informs the user that a transaction has successfully completed. its effects should persist even if the system crashes before all its changes are reflected on disk. Rn is a lossless-join decomposition of R . Inclusion Dependency: An Inclusion Dependency is a statement of the form that some columns of a relation are contained in other columns. What is a checkpoint and When does it occur? A Checkpoint is like a snapshot of the DBMS state.. Aggregation: A concept which is used to model a relationship between a collection of entities and relationships. DBMS ensures this by undoing the actions of incomplete transactions.DBMS Lab Manual Viva-Vice: 54. 57.. What is join dependency and inclusion dependency? Join Dependency: A Join dependency is generalization of Multivalued dependency. There is no set of sound and complete inference rules for JD. A foreign key constraint is an example of inclusion dependency. What is a Phantom Deadlock? In distributed deadlock detection. 56. Users should not have to worry about the effect of incomplete transactions. By taking checkpoints.Ravi 66 . 60. K. This information is stored in a collection of relations maintained by the system called metadata.. What is system catalog or catalog relation? How is better known as? A RDBMS maintains a description of all the data that it contains.. This property is called durability. R3. What do you mean by atomicity and aggregation? Atomicity: Either all actions are carried out or none are. . 55. It is used when we need to express a relationship among relationships. Such situations are called phantom deadlocks and they lead to unnecessary aborts.A JD {R1.

DBMS Lab Manual 11. Write a program to demonstrate %type and %rowtype attributes AIM: to demonstrate %type and %rowtype attributes HW/SW requirements: Processor RAM Hard Disk : : : AMD Athelon ™ 1.empno%type.put_line(‘empno is’ || my_empno || ‘ename is ‘ || my_ename).my_ename from emp where empno=no. K. My_Ename emp.ename into my_empno. PlSQL My_Empno emp. My_Emprow emp%rowtype. Else Dbms_output.67 GHz 256 MB 40 GB Software Declare : Oracle. If(SQl%rowcount=1) then Dbms_output. If(SQl%rowcount=1) then Dbms_output.Ravi 67 .empno || ‘ename is ‘ || my_emprow. Select empno. No number. Begin No:=&no.ename). Select * into my_emprow from emp where empno=no.ename%type. End if.put_line( ‘error’).put_line(‘empno is’ || my_emprow.

Valid Test Data Enter the value for no: 7788 OUTPUT empno is 7788 ename is vinay s. What are the different phases of transaction? Different phases are  Analysis phase  Redo Phase  Undo phase 62. End if. What is a query? A query with respect to DBMS relates to user commands that are used to interact with a data base. The query language can be classified into data definition language and data manipulation language.Ravi 68 . What do you mean by flat file database? It is a database in which there are no programs or user access languages. 63. It has no crossfile capabilities but is user-friendly and provides user-interface management. What is "transparent DBMS"? It is one. empno is 7788 ename is vinay s. Hierarchical schemas and their properties Network schema uses a graph data structure to organize records example for such a database management system is CTCG while a hierarchical schema uses a tree data structure example for such a system is IMS. End.DBMS Lab Manual Else Dbms_output. K. Viva-Vice 61. 64.put_line( ‘error’). Brief theory of Network. 65. which keeps its Physical Structure hidden from user.

Ravi 69 . it can be executed once for the parent query or it can be executed once for each row returned by the parent query. deletion and modification.CNUM) 67. A correlated subquery can be easily identified if it contains any references to the parent subquery columns in its WHERE clause.g. are used to bring back a set of rows to be used by the parent query. this is called a correlated subquery. E. What do you mean by Correlated subquery? Subqueries. If the subquery is executed for each row of the parent. K. Depending on how the subquery is written.CNUM = ORDER. The following example demonstrates a non-correlated subquery. or nested queries. What are the primitive operations common to all record management systems? Addition.DBMS Lab Manual 66. Columns from the subquery cannot be referenced anywhere else in the parent query. Select * From CUST Where '10/03/1990' IN (Select ODATE From ORDER Where CUST.

C number. B:=&b. C:=a/b. End if. PlSQL Dbms_output.Ravi 70 .DBMS Lab Manual 12.put_line(‘division is ‘ || C). Begin A:=&a. Valid Test Data: Enter the value for a: K. : Oracle.67 GHz 256 MB 40 GB Software Declare A number B number. Exception If (ZERO_DIVIDE) then Dbms_output. End. Write a exceptions program to demonstrate predefined AIM: to demonstrate predefined exceptions HW/SW requirements: Processor RAM Hard Disk : : : AMD Athelon ™ 1.put_line(‘b could not be zero’).

Storage Management. Lock Management 73. provides access to them. its primary functions are storing. Distribution Control. dispatches and schedules user requests. and the data dictionary. 74. and maps the actual physical storage location. and manages space usage within its table-space structures . Are the resulting relations of PRODUCT and JOIN operation the same? No. Security. Transaction Control. designed specifically for controlling data access. What are the unary operations in Relational Algebra? PROJECTION and SELECTION. Logging and Recovery. What is the job of the information stored in data-dictionary? The information in the data dictionary validates the existence of the objects. Memory Management. 70. retrieving. Process Control. K. manages memory caches and paging. JOIN: Concatenation of rows from one relation and related rows from another. Language Processing. Name the buffer in which all the commands that are typed in are stored ‘Edit’ Buffer 69. Name the sub-systems of a RDBMS I/O. Which part of the RDBMS takes care of the data dictionary? How Data dictionary is a set of tables and database objects that is stored in a special area of the database and maintained exclusively by the kernel.Ravi 71 . What is RDBMS KERNEL? Two important pieces of RDBMS architecture are the kernel. which consists of the system-level data structures used by the kernel to manage the database You might think of an RDBMS as an operating system (or set of subsystems). and securing data. 71.DBMS Lab Manual 10 Enter the value for b: 0 OUTPUT: b could not be zero Viva-Vice: 68. controls locking for concurrent resource usage. which is the software. PRODUCT: Concatenation of every row in one relation with every row in another. An RDBMS maintains its own list of authorized users and their associated privileges. 72.

If(B=0) then Raise Mydivide_zero. End if. else C:=a/b. : Oracle. PlSQL Mydivide_zero EXCEPTION. Dbms_output. Begin A:=&a.Ravi 72 .67 GHz 256 MB 40 GB Software Declare A number B number.DBMS Lab Manual 14. Write a program to demonstrate user defined exceptions AIM: to demonstrate user defined exceptions HW/SW requirements: Processor RAM Hard Disk : : : AMD Athelon ™ 1. Exception If (mydivide_zero) then K.put_line(‘division is ‘ || C). B:=&b. C number.

K.put_line(‘b could not be zero’). Define SQL and state the differences between SQL and other conventional programming Languages SQL is a nonprocedural language that is designed specifically for data access operations on normalized relational database structures. End if. The primary difference between SQL and other conventional programming languages is that SQL statements specify what data operations should be performed rather than how to perform them. you cannot access the database. Not only RDBMS takes care of locating data it also determines an optimal access path to store or retrieve the data 76. Name the three major set of files on disk that compose a database in Oracle There are three major sets of files on disk that compose a database. The control files and the redo logs support the functioning of the architecture itself. and available to Oracle for any data on the database to be useable. Without these files.DBMS Lab Manual Dbms_output. and the database administrator might have to recover some or all of the database using a backup. 78. open. Valid Test Data: Enter the value for a: 10 Enter the value for b: 0 OUTPUT: b could not be zero Viva-Vice: 75. How do you communicate with an RDBMS? You communicate with an RDBMS using Structured Query Language (SQL) 77. All the files are binary. All three sets of files must be present. if there is one. These are  Database files  Control files  Redo logs The most important of these are the database files where the actual data resides.Ravi 73 . End.

and all the Oracle background processes and user processes can use them. SMON (System Monitor).DBMS Lab Manual 79. provide functions for the user processes—functions that would otherwise be done by the user processes themselves Oracle database-wide system memory is known as the SGA. also known as Oracle background processes. The data and control structures in the SGA are shareable. What is an Oracle Instance? The Oracle system processes. LGWR (Log Writer). The combination of the SGA and the Oracle background processes is known as an Oracle instance 80. the system global area or shared global area. K. and PMON (Process Monitor). What are the four Oracle system processes that must always be up and running for the database to be useable The four Oracle system processes that must always be up and running for the database to be useable include DBWR (Database Writer).Ravi 74 .

if sal>=1000 and <2000 then update the salary to 2500.67 GHz 256 MB 40 GB Software : Oracle.xsal. PlSQL Declare Cursor my_cur is select empno. C number. Begin Open my_cur. if sal>=2000 and <=3000 then update the salary to 4000.Ravi 75 . Loop Fetch my_cur into xno. C:=c+1.sal%type.sal from emp. Create a Cursor which update the salaries of an Employee as follows.DBMS Lab Manual 15. 1. 2.*/ HW/SW requirements: Processor RAM Hard Disk : : : AMD Athelon ™ 1. Xsal emp. 3. C:=0. If(xsal<1000) then Update emp set sal=3000 where empno=xno. And also count the no. K. Xno emp.of records have been updated.empno%type. if sal<1000then update the salary to 1500.

put_line(c||’records have been successfully updated’). Sql>@a. Valid Test Data Before executing the cursor. Exit when my_cur%NOTFOUND End loop. ----------------------------------------------------------------7369 SMITH 7499 ALLEN 7521 WARD CLERK SALESMAN SALESMAN 7902 17-DEC-80 7698 20-FEB-81 7698 22-FEB-81 SAL 2000 1600 1250 20 300 500 30 30 EMPNO ENAME JOB K. C:=c+1. the records in emp table as follows Sql>select * from emp. End. End if. Close my_cur. OUTPUT: EMPNO ENAME JOB MGR HIREDATE SAL COMMD EPTNO . records have been successfully updated pl/sql procedure successfully completed.Ravi MGR HIREDATE COMM DEPTNO 76 . End if.DBMS Lab Manual Else if(xsal>=2000) and xsa<3000) then Update emp set sal=4000 where empno=xno. Dbma_output.sql.

In terms of accessing and using the data in the tables and other objects.DBMS Lab Manual -------. Viva-Vice: MANAGER 1250 1400 2850 7839 01-MAY-81 81. putting the database on different disk drives.---------. … 14 rows selected. the location of the database and redo logs. the number (or location) of the files is immaterial. Any database must have at least one control file.------------------------------------------------7566 JONES MANAGER 7839 02-APR-81 7698 28-SEP-81 2975 20 30 30 7654 MARTIN SALESMAN 7698 BLAKE … …. more than one files are used. The control file records the name of the database. K. The database files are fixed in size and never grow bigger than the size at which they were created Control Files The control files and redo logs support the rest of the architecture. How many of these files should a database have at least? Why? Database Files The database files hold the actual data and are typically the largest in size. You must have at least one database file but usually. Depending on their sizes.---------. Every time you add a new database or redo log file to the database.--------. although you typically have more than one to guard against loss. and the synchronization information to ensure that all three sets of files are always in step. What are database files. the information is recorded in the control files. the tables (and other objects) for all the user accounts can go in one database file—but that's not an ideal situation because it does not make the database structure very flexible for controlling access to storage for different users.--------. the date and time it was created. or backing up and restoring just part of the database.Ravi 77 . control files and log files.

Once assigned (when the row is first inserted into the database). which contains the row  The row within the block (because each block can hold many rows) The ROWID is used internally in indexes as a quick means of retrieving rows with a particular key value. there are twelve events for which you can define database triggers. What is database Trigger? A database trigger is a PL/SQL block that can defined to automatically execute for insert. Each Oracle block is numbered sequentially for each database file starting at 1. These Oracle blocks are the smallest unit of storage. These are the journals for the database. Application developers also use it in SQL statements as a quick way to access a row once they know the ROWID 83.DBMS Lab Manual Redo Logs Any database must have at least two redo logs. or deleted. 82. K. the entire block is not available for holding data. Increasing the Oracle block size can improve performance. Two blocks can have the same block address if they are in different database files. A database trigger can call database procedures that are also written in PL/SQL. but it should be done only when the database is first created. In the case of non-data loss failure. The ROWID consists of the following three components. updated. Oracle takes up some space to manage the contents of the block. 85. Name two utilities that Oracle provides. 84.  Oracle database file number. Oracle can apply the information in the redo logs automatically without intervention from the DBA.Ravi 78 . Along with the RDBMS software. Regardless of the block size. If any type of failure occurs. What is ROWID? The ROWID is a unique database-wide physical address for every row on every table. but it can grow. The trigger can e defined to execute once for the entire statement or once for every row that is inserted. For any one table. and delete statements against a table. the combination of which uniquely identifies the physical storage location of the row. The block size should be a multiple of the operating system block size. it never changes until the row is deleted or the table is dropped. update. These utilities are Export and Import. What is Oracle Block? Can two Oracle Blocks have the same address? Oracle "formats" the database files into a number of Oracle blocks when they are first created—making it easier for the RDBMS software to manage the files and easier to read data into the memory areas. which are use for backup and recovery. which contains the block with the rows  Oracle block address. the changes recorded in the redo logs can be used to bring the database to a consistent state without losing any committed transactions. the redo logs record all changes to the user objects or system objects. Oracle provides two utilities that you can use to back up and restore the database. This block header has a minimum size. The redo log files are fixed in size and never grow dynamically from the size at which they were created.

DBMS Lab Manual The Export utility dumps the definitions and data for the specified part of the database to an operating system binary file. all the changes made to the database cannot be recovered since the export was performed. recreates the definitions of objects. The Import utility reads the file produced by an export. K.Ravi 79 . The best you can do is recover the database to the time when the export was last performed. and inserts the data If Export and Import are used as a means of backing up and recovering the database.

Begin i:=1.j)=0) then K. create a procedure which generate all the prime numbers below the given number and count the no. PlSQL Create or replace procedure prime_proc(n IN number. HW/SW requirements: Processor RAM Hard Disk : : : AMD Athelon ™ 1. while(j<=i) loop if(mod(I.Ravi 80 .tot OUT number) as i number.DBMS Lab Manual 19. tot:=0.67 GHz 256 MB 40 GB Software : Oracle. c:=0. j number. c number. while(i<=n) loop j:=1.of prime numbers.

end if.are’||t). i:=i+1. end loop. tot:=tot+1.t). / Sql>procedure created. Valid Test Data: sql>set serveroutput on OUTPUT sql>/ K. declare t number. end if.DBMS Lab Manual c:=c+1. end loop.put_line(‘the total prime no .put_line(i). if(c=2) then dbms_output. begin prime_proc(10. dbms_output. j:=j+1. end.Ravi 81 . end.

87. Stored procedures are database objects that perform a user defined operation. Bad normalization ii. Stored procedures are used to reduce network traffic. all the changes made to the database cannot be recovered since the export was performed. What are stored-procedures? And what are the advantages of using them. Name two utilities that Oracle provides. recreates the definitions of objects. Tables derived from the ERD a) Are totally unnormalised b) Are always in 1NF c) Can be further denormalised d) May have multi-valued attributes (b) Are always in 1NF 89. K. Spurious tuples may occur due to i. Oracle provides two utilities that you can use to back up and restore the database. Along with the RDBMS software. A stored procedure can have a set of compound SQL statements. Viva-Vice 86.DBMS Lab Manual 2 3 5 7 The total prime no. A stored procedure executes the SQL commands and returns the result to the client.Ravi 82 . The best you can do is recover the database to the time when the export was last performed. The Export utility dumps the definitions and data for the specified part of the database to an operating system binary file. Theta joins iii. Updating tables from join a) i & ii b) ii & iii c) i & iii d) ii & iii (a) i & iii because theta joins are joins made on keys that are not primary keys. The Import utility reads the file produced by an export. 88.are 4 Pl/sql procedure successfully completed. and inserts the data If Export and Import are used as a means of backing up and recovering the database. which are use for backup and recovery. These utilities are Export and Import.

C} hence AC is the primary key. A B C is a set of attributes. B. Further B is not functionally dependent on key AC thus it is not in 2NF. where neither C is a Key nor B is a prime attribute. this it is not in 3NF.Ravi 83 . The functional dependency is as follows AB -> B AC -> C C -> B a) is in 1NF b) is in 2NF c) is in 3NF d) is in BCNF (a) is in 1NF since (AC)+ = { A. Thus the given FDs is in 1NF.DBMS Lab Manual 90. Since C B is a FD given. K.

empno%type.if sal<1000 then update the salry to 1500. C number. C:=0.Ravi 84 . Loop Fetch my_cur into xno. Xsal emp. create a procedure which updates the salaries of an employees as follows. C:=c+1.67 GHz 256 MB 40 GB Software : Oracle.xsal. 1.if sal>=1000 and <=2400 then update the salary to 2500.sal%type. Begin Open my_cur. 2. Xno emp. Else Is(xsal>=1000 and xsal<=2400) then K.DBMS Lab Manual 18. If(xsal<1000) then Update emp set sal=1500 where empno=xno.*/ HW/SW requirements: Processor RAM Hard Disk : : : AMD Athelon ™ 1. PlSQL Create or replace procedure myproc as Cursor my_cur is select empno.sal from emp.

Close my_cur. End loop. K. OUTPUT: Records have been successfully completed. Begin C:=a+b. End if. / Valid Test Data: Procedure created. Sql>exec myproc.DBMS Lab Manual Update emp set sal=2500 where empno=xno. Dbms_output.put_line(c||’records have been successfully updated’). End if.Ravi 85 . C:=c+1. Exit when my_cur%NOTFOUND. (Simple programs) */ Create or replace function add_fun(a number. End. /* create function which add two given numbers.b number) return Number as C number.

/*add_fun specification*/ Declare Result number.put_line(‘the sum of 10 and 20 is’||result).Ravi 86 . End.20).*/ /*function body*/ Create or replace function count_emp(esal number)return number as Cursor vin_cur as Select empno.sal%type. End. / Function created.sal from emp. Dbms_output.DBMS Lab Manual Return c. Sql>/ The sum of 10 and 20 is 30 Pl/sql procedure successfully completed. Xsal emp. Begin Result:=add_fun(10. Xno emp. /*create a function which count total no.of employees having salary less than 6000.empno%type. K.

close vin_cur. if(xsal<esal) then c:=c+1. Begin Ne:=count_emp(xsal). loop fetch vin_cur into xno.DBMS Lab Manual C number. Xsal number. return c. Begin Open vin_cur.xsal.put_line(xsal).Ravi 87 . Dbms_output. end loop. end. /*function specification*/ Declare Ne number. end if. / Function created. C:=0. K. exit when vin_cur%notfound.

the string should be in double quotes d) Error . application programs and queries submitted to the system. Viva-Vice: 91. 95. What is Buffer Manager? It is a program module. CUSTOMER From CUST_DTLS Where REGION = 'N' Order By CUSTOMER Union Select 'EAST'.Ravi 88 . which is responsible for fetching data from disk storage into main memory and deciding what data to be cache in memory.put_line(‘there are ‘||ne||. What is Storage Manager? It is a program module that provides the interface between the low-level data stored in database. / OUTPUT There are 8 employees. Since ORDER BY clause cannot be used in UNIONS 94. A dominant entity is the entity a) on the N side in a 1 : N relationship b) on the 1 side in a 1 : N relationship c) on either side in a 1 : 1 relationship d) nothing to do with 1 : 1 or 1 : N relationship (b) on the 1 side in a 1 : N relationship 93. Select 'NORTH'.the string in single quotes 'NORTH' and 'SOUTH' c) Error . K. In mapping of ERD to DFD a) entities in ERD should correspond to an existing entity/store in DFD b) entity in DFD is converted to attributes of an entity in ERD c) relations in ERD has 1 to 1 correspondence to processes in DFD d) relationships in ERD has 1 to 1 correspondence to flows in DFD (a) entities in ERD should correspond to an existing entity/store in DFD 92. CUSTOMER From CUST_DTLS Where REGION = 'E' Order By CUSTOMER The above is a) Not an error b) Error .ORDER BY clause (d) Error .DBMS Lab Manual Dbma_output.the ORDER BY clause.employees’). End.

K. the only option available in the event of data file loss is restoring all the files from the latest backup. 97. that the files of the tablespace are to backed up. What are cursors give different types of cursors. What are stand-alone procedures? Procedures that are not part of a package are known as stand-alone because they independently defined. These types of procedures are not available for reference from other Oracle tools. What is Authorization and Integrity manager? It is the program module. A good example of a stand-alone procedure is one written in a SQL*Forms application. So different means of backing up database must be used — the hot backup. All work performed on the database since the last backup is lost. The cold backup is not an available option. The users can continue to make full use of the files. usually from the disk directly to tape. What is Transaction Manager? It is a program module. on a tablespace-by-tablespace basis. If a cold backup is performed. which slows execution. The language supports the use two types of cursors  Implicit  Explicit 101. The database must be running in ARCHIVELOG mode for the hot backup option. and control file) when the instance is shut down. Issue a SQL command to indicate to Oracle.  Hot Backup: Some sites (such as worldwide airline reservations systems) cannot shut down the database while making a backup copy of the files. 98. PL/SQL uses cursors for all database information accesses statements. including making changes to the data.Ravi 89 . he/she can use the operating system to copy those files to the desired backup destination. remains in a consistent state despite system failures and concurrent transaction execution proceeds without conflicting. Once the user has indicated that he/she wants to back up the tablespace files. which ensures that database. What is File Manager? It is a program module. This is a straight file copy. What is cold backup and hot backup (in case of Oracle)?  Cold Backup: It is copying the three sets of files (database files. which tests for the satisfaction of integrity constraint and checks the authority of user to access data. 100.DBMS Lab Manual 96. You must shut down the instance to guarantee a consistent copy. which manages the allocation of space on disk storage and data structure used to represent information stored on a disk. 99. Another limitation of stand-alone procedures is that they are compiled at run time. redo logs.

Ravi 90 .  Transitive rule: If {X Y. What are Armstrong rules? How do we say that they are complete and/or sound The well-known inference rules for FDs  Reflexive rule : If Y is subset or equal to X then X Y. Set X+ = X 2. For each attribute A in K a. How can you find the minimal key of relational schema? Minimal key is one which can identify each tuple of the given relation schema uniquely.  Pseudo Transitive rule : If {X Y. They are sound because it is enough if a set of FDs satisfy these three. given set of FDs F 1. Repeat steps 2 and 3 until Old X+ = X+ Algo. Compute (K – A)+ with respect to F b. The database is restored to the most consistent state without any loss of committed transactions. I Determining X+. 102.DBMS Lab Manual If a data loss failure does occur.. Y Z} then X Z.  Augmentation rule: If X Y then XZ YZ. then some dependency is lost in the decomposition. dependency preservation states that the closure of the union of the projection of F on each decomposed relation Ri is equal to the closure of F. given set of FDs F 1. i. 103. Of these the first three are known as Amstrong Rules. For finding the minimal key it is required to find the closure that is the set of all attributes that are dependent on any given set of attributes under the given set of functional dependency. Algo.II Determining minimal K for relation schema R. X Z} then X YZ. closure for X.  Union or Additive rule: If {X Y. WY Z} then WX Z. the lost database files can be restored using the hot backup and the online and offline redo logs created since the backup was done.  Decomposition rule : If X YZ then X Y. K.e. For each FD Y Z in F and if Y belongs to X+ then add Z to X+ 4. They are called complete because using these three rules we can generate the rest all inference rules. Set Old X+ = X+ 3. Set K to R that is make K a set of all attributes in R 2. If (K – A)+ = R then set K = (K – A)+ 104. ((Π R1(F)) U … U (Π Rn(F)))+ = F+ if decomposition is not dependency preserving. What do you understand by dependency preservation? Given a relation R and a set of FDs F.

Retroactive and Simultaneous Update. What is meant by Proactive. What are the different types of JOIN operations? Equi Join: This is the most common type of join which involves only equality comparisions. 106. The disadvantage in this type of join is that there K.DBMS Lab Manual 105. world .Ravi 91 . Proactive Update: The updates that are applied to database before it becomes effective in real Retroactive Update: The updates that are applied to database after it becomes effective in real world . Simulatneous Update: The updates that are applied to database at the same time when it becomes effective in real world .

and then executes it? RUN 7. alter. index. What are the privileges that can be granted on a table by a user to others? Insert. <>. What command is used to get back the privileges offered by the GRANT command? REVOKE 12. ^= all denote the same operation. What operator tests column for the absence of data? IS NULL operator 4. all 11. True 9. SOME. including tables? Data Definition Language (DDL) 2. references. Which system tables contain information on privileges granted and privileges obtained? USER_TAB_PRIVS_MADE. Which is the subset of SQL commands used to manipulate Oracle Database structures. True 10. update. State true or false.DBMS Lab Manual SQL Questions: 1. State true or false. What operator performs pattern matching? LIKE operator 3. Which command executes the contents of a specified file? START <filename> or @<filename> 5. Will the outputs of the above two commands differ? K. Which command displays the SQL command in the SQL buffer. ANY are operators in SQL. DELETE FROM EMP. execute.Ravi 92 . EXISTS. !=. TRUNCATE TABLE EMP. What is the parameter substitution symbol used with INSERT INTO command? & 6. Which system table contains information on constraints on all the tables created? USER_CONSTRAINTS 14. select. USER_TAB_PRIVS_RECD 13. What are the wildcards used for pattern matching? _ for single character substitution and % for multi-character substitution 8. delete.

Which date function is used to find the difference between two dates? MONTHS_BETWEEN 21. '**'). If the WHERE condition is true.'1234567890'. The null values in the commission column will be replaced by 0 and added to salary. AS SELECT command Explanation : To copy only the structure.'!'). What will be the output of the following query? SELECT DECODE(TRANSLATE('A'. What is the advantage of specifying WITH GRANT OPTION in the GRANT command? K. '!').. Here the table name starts with an '&' symbol. 16. but TRUNCATE operation cannot be rolled back. Hence DELETE operation can be rolled back. Variable names should start with an alphabet. 'AN'. TROUBLETHETROUBLE 18. '1'. CREATE TABLE NEWTABLE AS SELECT * FROM EXISTINGTABLE WHERE 1=2. WHERE clause can be used with DELETE and not with TRUNCATE. then all the rows or rows satisfying the condition will be copied to the new table. 20. 'NO' ). Why does the following command give a compilation error? DROP TABLE &TABLE_NAME.'*'. What does the following query do? SELECT SAL + NVL(COMM. 19.'YES'. This displays the total salary of all employees.Ravi 93 . Answer : NO Explanation : The query checks whether a given string is a numerical digit.'1111111111').DBMS Lab Manual Both will result in deleting all the rows in the table EMP. 22.0) FROM EMP. What command is used to create a table by copying the structure of another table? Answer : CREATE TABLE .'TROUBLE') FROM DUAL. What is the difference between TRUNCATE and DELETE commands? TRUNCATE is a DDL command whereas DELETE is a DML command. 17. 15. the WHERE clause of the SELECT command should contain a FALSE statement as in the following. What will be the output of the following query? SELECT REPLACE(TRANSLATE(LTRIM(RTRIM('!! ATHEN !!'.

comm = 1000 25. 1200 K. sal = 11000. Which function is used to find the largest integer less than or equal to a specific value? FLOOR 28.Ravi 94 . What is the output of the following query? SELECT TRUNC(1234.5678. COMM = SAL*0. 26. a parent table can be dropped even when a child table exists. It is used to describe a schema as well as to retrieve rows from table in descending order. What is the use of the DROP option in the ALTER TABLE command? It is used to drop constraints specified on the table. What is the use of DESC in SQL? Answer : DESC has two purposes. Explanation : The query SELECT * FROM EMP ORDER BY ENAME DESC will display the output sorted on ENAME in descending order. 24.-2) FROM DUAL.1. 27. 23.DBMS Lab Manual The privilege receiver can further grant the privileges he/she has obtained from the owner to any other user. What is the use of CASCADE CONSTRAINTS? When this clause is used with the DROP command. What is the value of ‘comm’ and ‘sal’ after executing the following query if the initial value of ‘sal’ is 10000? UPDATE EMP SET SAL = SAL + 1000.

BPB. oracle Teach Your Self SQL/PLSQL using oracle 8i and 9i with SQLJ.  Abbey.TMH-2000 Loney.TMH-2000 Bayross.TMH-2000.Ravi 95 . oracle 8i-A beginners guide.TMH-2000 Loney. 2002.DBMS Lab Manual REFERENCES: SCOTT Urman. oracle 9i-the complete reference. oracle 8i-the complete reference. oracle 8i-PL/SQL programming.     K.

1 GURU NANAK Engineering College Ibrahimpatnam._____ Department of ________________________ Name Class / Year / Semester Roll No. Subject Branch Date of Submission : : : : : : ______________________________________ B.Ravi 96 .) Assignment / Record No . R R District – 501 506 (A. Tech _____ Year _________ Semester _________________________ _________________________ _________________________ _____ / _____ / __________ ________________ Student Signature ________________ Faculty Signature K.DBMS Lab Manual Annexure . P.

2 Index Page S. Date Program / Experiment Page No.Ravi 97 . No. Sign / Remarks K.DBMS Lab Manual Annexure .

Tech ______ Year ________ Semester _________________________ _________________________ _________________________ Has successfully completed the course of programs / experiments prescribed by Jawharlal Nerhu Technological Univeristy of the department during the academic year 200__ . Hyderabad (A.) Department of ________________________ This is to certify that Name Class / Year / Semester Roll No. Subject Branch : : : : : ______________________________________ B. P.200 __.) (Sponsored by: Guru Nanak Educational Society. R R District – 501 506 (A.DBMS Lab Manual Annexure . P.3 GURU NANAK Engineering College Ibrahimpatnam.Ravi ________________ Department Head 98 . ________________ Faculty Incharge K.

DBMS Lab Manual K.Ravi 99 .

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->