DBMS Lab Manual
DBMS Lab Manual
I. Consider the Insurance database given below. The primary keys are underlined and
the data types are specified.
(i) Create the above tables by properly specifying the primary keys and the
foreign keys.
(ii) Enter at least five tuples for each relation.
(iii) Demonstrate how you
a. Update the damage amount for the car with a specific Regno in the
accident with report number 12 to 25000.
b. Add a new accident to the database.
(iv) Find the total number of people who owned cars that were involved in accidents
in 2008.
(v) Find the number of accidents in which cars belonging to a specific model
were involved.
(vi) Generate suitable reports.
(vii) Create suitable front end for querying and displaying the results.
II. Consider the following relations for an order processing database application in a
company.
III. Consider the following database of student enrollment in courses & books adopted for each
course.
(i) Create the above tables by properly specifying the primary keys and the
foreign keys.
(ii) Enter at least five tuples for each relation.
(iii) Demonstrate how you add a new text book to the database and make this
book be adopted by some department.
(iv) Produce a list of text books (include Course #, Book-ISBN, Book-title) in the
alphabetical order for courses offered by the ‘CS’ department that use more
than two books.
(v) List any department that has all its adopted books published by a specific
publisher.
(vi) Generate suitable reports.
(vii) Create suitable front end for querying and displaying the results.
(i) Create the above tables by properly specifying the primary keys and the
foreign keys.
(ii) Enter at least five tuples for each relation.
(iii) Give the details of the authors who have 2 or more books in the catalog and
the price of the books is greater than the average price of the books in the
catalog and the year of publication is after 2000.
(iv) Find the author of the book which has maximum sales.
(v) Demonstrate how you increase the price of books published by a specific
publisher by 10%.
(vi) Generate suitable reports.
(vii) Create suitable front end for querying and displaying the results.
(i) Create the above tables by properly specifying the primary keys and the
foreign keys
(ii) Enter at least five tuples for each relation
(iii) Find all the customers who have at least two accounts at the Main branch.
(iv) Find all the customers who have an account at all the branches located in a
specific city.
(v) Demonstrate how you delete all account tuples at every branch located in a
specific city.
(vi) Generate suitable reports.
(vii) Create suitable front end for querying and displaying the results.
Instructions:
1. The exercises are to be solved in an RDBMS environment like Oracle or DB2.
2. Suitable tuples have to be entered so that queries are executed correctly.
3. Front end may be created using either VB or VAJ or any other similar tool.
4. The student need not create the front end in the examination. The results of the
queries may be displayed directly.
5. Relevant queries other than the ones listed along with the exercises may also
be asked in the examination.
6. Questions must be asked based on lots.
Table of Contents
1. Insurance Database
7. Viva Questions
Department of Information Science and Engineering
I. Consider the Insurance Database given below. The primary keys are underlined and the data
types are specified. Write the ER Diagram
1
Did
Regno
1
Repno
Damt
Participated
Accident
Repno
Location
Department of Information Science and Engineering
1) Create the above tables by properly specifying the primary keys and the foreign
keys.
PERSON
CAR
ACCIDENT
OWNS
DRIVER_ID# REGNO
1111 KA04Q2301
1111 KA05P1000
2222 KA03L1234
3333 KA03L9999
4444 KA01P4020
PARTICIPATED
4) Demonstrate how you update damage amount for the car with a specific regno in
accident with reportno 12 to 25000
UPDATE PARTICIPATED
SET DAMAGE_AMT=25000
WHERE REPORT_NO =12 AND REGNO='KA04Q2301';
Department of Information Science and Engineering
Output
PARTICIPATED
Output
ACCIDENT
5) Find the total no of people who owned cars that were involved in accidents 2002.
Output
COUNT (O.DRIVER_ID#)
---------------------------------
3
6) Find the number of accidents in which cars belonging to a specific model were involved.
SELECT COUNT(*),MODEL
FROM ACCIDENT A, PARTICIPATED P, CAR C
WHERE A.REPORT_NO=P.REPORT_NO
AND
P.REGNO=C.REGNO
AND
C.MODEL='MARUTHI-DX';
Output
II. Consider the following relations for an Order Processing Database application in a
company. The primary keys are underlined and the data types are specified. Write the ER
Diagram
CUSTOMER (CUST #: INT, CNAME: STRING, CITY: STRING)
ORDER (ORDER #: INT, ODATE: DATE, CUST #: INT, ORD-AMT: INT)
ITEM (ITEM #: INT, UNIT PRICE: INT)
ORDER - ITEM (ORDER #: INT, ITEM #: INT, QTY: INT)
SHIPMENT (ORDER #: INT, WAREHOUSE#: INT, SHIP-DATE: DATE)
WAREHOUSE (WAREHOUSE #: INT, CITY: STRING)
CustName ItemNo
OrderNo
OrderNo Unitprice
CustNo
ItemN Shipdate
City
Qty
Warehouse
OrderNo Odate
City
Order
CustNo WarehouseNo
Orderamt
1) Create the above tables by properly specifying the primary keys and
The foreign keys
Department of Information Science and Engineering
PRIMARY KEY(ORDER#,WAREHOUSE#)
);
CUSTOMER
ORDER
ITEM
ITEM# UNITPRICE
1 2500
2 5000
3 1000
4 5
5 200
ORDER_ITEM
WAREHOUSE
WAREHOUSE# CITY
1 BLORE
2 KOLAR
3 CHITTOR
4 MLORE
5 MYSORE
Department of Information Science and Engineering
SHIPMENT
ORDER# WAREHOUSE# SHIPDATE
1 1 30-APR-06
2 2 29-APR-06
3 2 24-APR-06
4 5 30-APR-06
5 3 01-JUN-06
6 1 01-JUN-06
OUTPUT
4) List the order# for orders that where shipped from all the warehouse
that the company has in specific city.
SELECT ORDER#
FROM WAREHOUSE W, SHIPMENT S
WHERE W.WAREHOUSE#=S.WAREHOUSE# AND CITY='BLORE';
Department of Information Science and Engineering
OREDER#
1
5) Demonstrate how to delete item 10 from the item table and make that field null in
the ORDER-ITEM table
SELECT CONSTRAINT_NAME,CONSTRAINT_TYPE
FROM USER_CONSTRAINTS
WHERE TABLE_NAME='ORDER_ITEM';
CONSTRAINT_NAME C
-------------------------------------------- -
SYS_C002734 P
SYS_C002735 R
SYS_C002736 R
ITEM# UNITPRICE
1 2500
2 5000
3 1000
4 -5
III. Consider the following database of student enrollment in courses & books adopted for each
course. The primary keys are underlined and the data types are specified. Write the ER Diagram
name CourseNo
RegNo RegNo CourseNo Cname
Major Dept
Marks
Bdate Book
CourseNo adoption
Sem
Sem
BookISBN
TEXT
Publisher
BookTitle
BookISBN Author
Department of Information Science and Engineering
1) Create the above tables by properly specifying the primary keys and the foreign
keys
ISBN NUMBER(4),
PRIMARY KEY(COURSE#,SEM),
FOREIGN KEY(COURSE#) REFERENCES COURSE(COURSE#),
FOREIGN KEY(ISBN) REFERENCES TEXT(ISBN)
);
STUDENT
COURSE
1 MCA MANAG
2 MBA MANAG
3 ISE CS
4 CSE CS
5 CIV CIVIL
Department of Information Science and Engineering
ENROLL
TEXT
BOOK_ISBN BOOK_TITLE PUBLISHER AUTHOR
BOOK_ADOPTION
3 111003 CS
3 111001 DBMS
4 111005 SE
4 111003 OS
4 111006 AMP
OUTPUT
DEPT
CS
Department of Information Science and Engineering
IV. The following tables are maintained by a book dealer. The primary keys are underlined and
the data types are specified. Write the ER Diagram
Name Catalogid
Authorid Bookid Publisheri
Title Pname
city
Catalog Publisher
1
Author N AuthorIn Country
Country
city
Publisher Order
Details
Author
OrderNo
Qty
Bookid
Category
Categoryid
1) Create the above tables by properly specifying the primary keys and
the foreign keys
);
2) INSERT THE RECORDS INTO THE RELATIONS
AUTHOR
AUTHORID NAME CITY COUNTRY
---------- --------------- ------------------ -----------------
101 ABC DELHI INDIA
102 TONY HAYHOOD USA
103 GHI PATNA INDIA
104 JKL BELM SRILANKA
105 MND BANGALORE INDIA
PUBLISHER
CATEGORY
CATEGORYID DESCRIPTIONM
-------------------- ------------------------
10001 cs
10002 med
10003 bio
10004 meteor
10005 mech
Department of Information Science and Engineering
CATALOG
ORDER_DETAILS
4) GIVE THE DETAILS OF THE AUTHORS WHO HAVE TWO OR MORE BOOKS IN
THE CATALOG AND THE PRICE OF THE BOOKS IS GREATER THAN THE
AVERAGE PRICE OF THE BOOKS IN THE CATALOG & THE YEAR OF
PUBLICATION IS AFTER 2000.
Output
NAME
---------
DEF
Output
V. Consider the following database for a banking enterprise. The primary keys are underlined
and the data types are specified. Write the ER Diagram
Account Branch
Account Branch
Cname assets
AccNo
Cname
Loan
branch
Depositor
Cname
(
LOAN-NO NUMBER(6),
BRANCH_NAME VARCHAR2(15),
AMOUNT NUMBER(10,4),
PRIMARY KEY(LOAN-NO),
FOREIGN KEY(BRANCH_NAME) REFERENCES
BRANCH(BRANCH_NAME)ON DELETE CASCADE
);
BRANCH
CUSTOMER
ACCOUNT
DEPOSITOR
CUSTOMER-NAME ACCNO
AJAY 1
SUMUKH 2
SANTA 3
AMIT 4
RAJUTH 5
AJAY 7
LOAN
BORROWER
LOANNO
Department of Information Science and Engineering
CUSTOMERNAME
AJAY 10
SUMUKH 20
SANTA 30
AMIT 40
RAJATH 50
>SELECT D.CUSTOMERNAME
FROM DEPOSITOR D, ACCOUNT A, BRANCH B
WHERE D.ACCNO=A.ACCNO AND
A.BRANCHNAME=B.BRANCHNAME AND
B.BRANCHCITY=’CHENNAI’
GROUP BY D.CUSTOMERNAME
HAVING COUNT(A.BRANCHNAME)=(SELECT COUNT(X.BRANCHNAME)
FROM BRANCH X
WHERE X.BRANCHCITY=’CHENNAI’);
Output
CUSTOMERNAME
------------------------
AJAY
AMIT
RAJANT
SANTA
SUMUKH
>SELECT D.CUSTOMERNAME
FROM DEPOSITOR D, ACCOUNT A, BRANCH B
WHERE D.ACCNO=A.ACCNO AND
A.BRANCHNAME=B.BRANCHNAME AND
B.BRANCHCITY=’CHENNAI’
GROUPBY C.CUSTOMERNAME
HAVING COUNT (*)>=2;
Output
CUSTOMERNAME
-------------------------
Department of Information Science and Engineering
AJAY
6) DEMONSTRATE HOW YOU DELETE ALL THE TUPLES AT EVERY BRANCH LOCATED
IN A PARTICULAR CITY
Output
SQL> /
3 ROWS DELETED
EXTRA QUERIES
1) SUPPOSE THAT ANNUAL INTEREST PAYMENTS ARE BEING MADE AND ALL
BRANCHES ARE TO BE INCREASED BY 3%.
4) FIND THE LOAN NUMBER OF THOSE LOANS WITH LOAN AMOUNTS BETWEEN
10000 AND 40000.
6) FIND ALL THE CUSTORES WHO HAVE AN ACCOUNT AND A LOAN AT THE
BANK.
10) FIND THE NAMES OF ALL BRANCHES THAT HAVE AN ASSET VALUE
GREATER THAN THAT OF EACH BRANCH IN BANGALORE.
Create the necessary FORM using label, textbox & button controls.
STEP 2:
3. Add the ADODC from the ToolBox to the form & name the
control adcBranch
4. Set ConnectString, CommandType & Record Source properties of the ADO
Data Control as follows
5. Right click on adcBranch data control & select ADODC Properties
6. To set the connection [property click on BUILD button & you get a
Data Link Dialog box as follows
Department of Information Science and Engineering
9. Click on RecordSource TAB & select 2 - adCmdTable. Wait till the tables
are listed in the Table combo Box
Department of Information Science and Engineering
STEP 3:
1. Double click on the New button & add the following code
2. Double click on the Save button & add the following code
3. Double click on the Update button & add the following code
Private Sub Update_Click()
adcBranch.Recordset.Update
adcBranch.Recordset.Save
MsgBox "Record Updated Successfully"
End Sub
4. Double click on the Delete button & add the following code
VIVA QUESTIONS