Beruflich Dokumente
Kultur Dokumente
INDEX
1. INSURANCE DATABASE 2
3. STUDENT DATABASE 23
4. BOOK DATABASE 34
5. BANKING DATABASE 44
1 www.bookspar.com
www.bookspar.com | Website for students | VTU NOTES
PROBLEM 1
PROBLEM STATEMENT:
Consider the Insurance Database given below. The primary keys are
underlined and the datatypes are specified.
i) Create the above tables by properly specifying the primary keys and the
foreign keys.
iv) Find the total number of people who owned cars that were involved in
accidents in 2008.
vii) Create a suitable front end for querying and displaying the results.
2 www.bookspar.com
www.bookspar.com | Website for students | VTU NOTES
SCHEMA DESCRIPTION:
PERSON CAR
DRIVER_ID NAME ADDRESS REG_NO MODEL YEAR
PARTICIPATED
ACCIDENT
REPORTNO DATE LOCATION
OWNS
DRIVER_ID REG_NO
-----------------
------------
3 www.bookspar.com
www.bookspar.com | Website for students | VTU NOTES
ER DIAGRAM:
MODEL
REGNO YEAR
CAR
OWNS
NAME DRIVER_ID
PERSON
ADDRESS
DAMAGEAMT
PARTICIPATED
ACCIDENT
REPORT_NO LOCATION
DATE
4 www.bookspar.com
www.bookspar.com | Website for students | VTU NOTES
TABLE CREATION
Table created.
TABLE DESCRIPTION
INSERTING TUPLES
1 row created.
5 www.bookspar.com
www.bookspar.com | Website for students | VTU NOTES
TABLE CREATION
Table created.
TABLE DESCRIPTION
INSERTING TUPLES
1 row created.
SQL> insert into car values(2000,innova,2005);
SQL> insert into car values(3000,omni,1999);
SQL> insert into car values(4000,zen,2004);
SQL> insert into car values(5000,scorpio,2008);
6 www.bookspar.com
www.bookspar.com | Website for students | VTU NOTES
TABLE CREATION
Table created.
TABLE DESCRIPTION
INSERTING TUPLES
1 row created.
7 www.bookspar.com
www.bookspar.com | Website for students | VTU NOTES
TABLE CREATION
Table created.
TABLE DESCRIPTION
INSERTING TUPLES
1 row created.
DRIVER_ID REGNO
-----------------------------
1 1000
2 2000
3 3000
4 4000
5 5000
8 www.bookspar.com
www.bookspar.com | Website for students | VTU NOTES
TABLE CREATION
Table created.
TABLE DESCRIPTION
INSERTING TUPLES
1 row created.
9 www.bookspar.com
www.bookspar.com | Website for students | VTU NOTES
QUERIES
1 row updated.
RESULT
EXPLANATION
The SQL command Update is used to change the value of attribute damage in table participated.
The where clause provides the condition which selects the tuples in where regno= 3000 and repno
lies between 12 and 25000.
1 row created.
RESULT
10 www.bookspar.com
www.bookspar.com | Website for students | VTU NOTES
EXPLANATION
The insert command is used here to insert the tuples into the accident tables. The attributes are
specified in the braces.
2. Find the total number of people who owned cars that were involved in accidents
in 2008
RESULT
COUNT(P.DRIVER_ID)
----------------------------------
3
EXPLANATION
The condition pa.repno and a.repno selects appropriate tuples with date ending in 08.The count
function counts the number of such tuples.
3. Find the number of accidents in which cars belonging to a specific model were
involved
RESULT
COUNT(A.REPNO)
--------------------------
2
EXPLANATION
The three relations are joined at their attributes correspondingly and the tuples with model name
zen are selected and count function counts the number of such tuples .
11 www.bookspar.com
www.bookspar.com | Website for students | VTU NOTES
PROBLEM-2
PROGRAM STATEMENT:
i) Create the above tables by properly specifying the primary keys and the
foreign keys.
iv) List the order# for the orders that were shipped from all the warehouses
that the company has in a specific city.
v) Demonstrate how you delete an item from the ITEM table and make that
field null in the ORDER-ITEM table.
vii) Create a suitable front end for querying and displaying the results.
12 www.bookspar.com
www.bookspar.com | Website for students | VTU NOTES
SCHEMA DESCRIPTION:
CUSTOMER
CUST_NO CNAME CITY
ORDER WAREHOUSE
ORDER_NO ODATE CUST_NO ORD_AMT WARE_NO CITY
--------------
ORDER_ITEM
ITEM
ITEM_NO UNIT_PRICE
SHIPMENT
ORDER_NO WARE_NO SHIP_DATE
------------------ ---------------
13 www.bookspar.com
www.bookspar.com | Website for students | VTU NOTES
ER DIAGRAM:
CNAME
CUST_ID C_CITY
CUSTOMER
PLACE
ORD_AMT ORDER_N
S O
ORDER O_DATE
QTY
SHIPMEN
T
ORDER_ITE
M ORD_AM
T
WAREHOUSE
ITEM
WARE_NO CITY
UNIT_PRICE
ITEM_NO
14 www.bookspar.com
www.bookspar.com | Website for students | VTU NOTES
TABLE CREATION
Table created.
TABLE DESCRIPTION
INSERTING TUPLES
1 row created.
15 www.bookspar.com
www.bookspar.com | Website for students | VTU NOTES
TABLE CREATION
Table created.
TABLE DESCRIPTION
INSERTING TUPLES
16 www.bookspar.com
www.bookspar.com | Website for students | VTU NOTES
TABLE CREATION
TABLE DESCRIPTION
INSERTING TUPLES
1 row created.
SQL> insert into items values(2,2000);
SQL> insert into items values(3,1320);
SQL> insert into items values(4,2300);
SQL> insert into items values(5,1200);
ITEMNO PRICE
--------------------------------
1 2000
2 2000
3 1320
4 2300
5 1200
17 www.bookspar.com
www.bookspar.com | Website for students | VTU NOTES
TABLE CREATION
Table created.
TABLE DESCRIPTION
INSERTING TUPLES
1 row created.
18 www.bookspar.com
www.bookspar.com | Website for students | VTU NOTES
TABLE CREATION
Table created.
TABLE DESCRIPTION
INSERTING TUPLES
1 row created.
WARENO CITY
---------------------------------
1 delhi
2 poona
3 delhi
4 madras
5 hyd
19 www.bookspar.com
www.bookspar.com | Website for students | VTU NOTES
TABLE CREATION
Table created.
TABLE DESCRIPTION
INSERTING TUPLES
20 www.bookspar.com
www.bookspar.com | Website for students | VTU NOTES
QUERIES
RESULT
EXPLANATION
This query produces the list of customers with no of orders. The three relations are joined at
corresponding attributes. The count function is used to display the names. The average is the
product of quantity and price.
2. List the order# for orders that were shipped from all the warehouses that the
company has in a specific city.
RESULT
ORDNO
----------
11
13
EXPLANATION
The two tables warehouse and shipment are joined and the tuples with given city name are
selected and orderno is selected.
21 www.bookspar.com
www.bookspar.com | Website for students | VTU NOTES
3. Demonstrate how you delete item# from the ITEM table and make that field null
in the ORDER_ITEM table
SQL> delete
from items
where itemno=1;
1 row deleted.
RESULT
ITEMNO PRICE
--------------------------------
2 2000
3 1320
4 2300
5 1200
EXPLANATION
Since the attribute itemno is a primary key, we have eliminated that constraint and after that the
tuples with the indicated itemno are deleted. Also in the order_item table the tuple which
contained itemno 10 has been made null.
22 www.bookspar.com
www.bookspar.com | Website for students | VTU NOTES
PROBLEM 3
PROBLEM STATEMENT:
i) Create the above tables by properly specifying the primary keys and the
foreign keys.
iii) Demonstrate how you add a new text book to the database and make this
book be adopted by some department.
v) List any department that has all its adopted books published by a specific
publisher.
vii) Create suitable front end for querying and displaying the results.
23 www.bookspar.com
www.bookspar.com | Website for students | VTU NOTES
SCHEMA DESCRIPTION:
STUDENT COURSE
REG_NO NAME MAJOR BDATE COURSE_NO CNAME CITY
ENROLL
REG_NO COURSE_NO SEM MARKS
------------- ------------------
BOOK ADOPTION
COURSE_NO BOOK_ISBN SEM
TEXT
BOOK_ISBN BOOK_TITLE PUBLISHER AUTHOR
24 www.bookspar.com
www.bookspar.com | Website for students | VTU NOTES
ER DIAGRAM:
NAME MAJOR
B_DATE
STUDENT
REG_N
O
ENROLL MARKS
SEM
CNAME
COURSE
COURS DEPT
E
BOOK_ADOPTIO
N
SEM
TEXT
ISBN
TITLE
AUTHOR
PUBLISHER
25 www.bookspar.com
www.bookspar.com | Website for students | VTU NOTES
TABLE CREATION
Table created.
TABLE DESCRIPTION
INSERTING TUPLES
1 row created.
26 www.bookspar.com
www.bookspar.com | Website for students | VTU NOTES
TABLE CREATION
Table created.
TABLE DESCRIPTION
INSERTING TUPLES
1 row created.
27 www.bookspar.com
www.bookspar.com | Website for students | VTU NOTES
TABLE CREATION
Table created.
TABLE DESCRIPTION
INSERTING TUPLES
1 row created.
28 www.bookspar.com
www.bookspar.com | Website for students | VTU NOTES
TABLE CREATION
Table created.
TABLE DESCRIPTION
INSERTING TUPLES
29 www.bookspar.com
www.bookspar.com | Website for students | VTU NOTES
new 2: ('103','003','5','590')
TABLE CREATION
Table created.
TABLE DESCRIPTION
INSERTING TUPLES
30 www.bookspar.com
www.bookspar.com | Website for students | VTU NOTES
1 row created.
QUERIES
1. Demonstrate how you add a new text book to the database and make this book be
adopted by some department
1 row created.
1 row created.
RESULT:
31 www.bookspar.com
www.bookspar.com | Website for students | VTU NOTES
6 rows selected.
6 rows selected.
EXPLANATION
INSERT can be used to add a single tuple to a relation. Thus information about a new text book
can be added to the TEXT entity using INSERT command. The new text book can be made to be
adopted by some department using INSERT. The values which are added to the
BOOK_ADOPTION contain COURSE and SEM of the department and semester which uses the
textbook, along with the BOOK_ISBN of the textbook through which other information of the
textbook can be obtained.
2.Produce a list of textbooks in the alphabetic order for courses offered by the CSE
department that use more than two books
32 www.bookspar.com
www.bookspar.com | Website for students | VTU NOTES
where course=c.course
group by course
having count(course)>2)
order by book_title;
RESULT
EXPLANATION
The first nested query selects the Departments which use more than two books. To select the
departments EXIST function is used to check whether there are any department which use more
than two books. In the outer query, we select the courseno, book_isbn and book_title of the
textbooks for courses offered by the CSE department. In the outer query, the join condition
C.COURSE= BA.COURSE relates the COURSE and BOOK_ADOPTION and the condition
DEPT= CSE is a selection condition. ORDER-BY clause is used to order the tuples in the result
of query according to the BOOK_TITLE
3. List any department that has all its adopted books published by a specific
publisher.
RESULT
DEPT
--------------------------
ise
EXPLANATION
The outer query selects the distinct departments for the specified publisher venugopal. The inner
query selects all the publishers for all the books adopted by the selected department. The keyword
all is used to check whether whether the department has all its adopted books publisher by
venugopal.
33 www.bookspar.com
www.bookspar.com | Website for students | VTU NOTES
PROGRAM -4
PROGRAM STATEMENT:
i) Create the above tables by properly specifying the primary keys and the
foreign keys.
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.
vii) Create a suitable front end for querying and displaying the results.
34 www.bookspar.com
www.bookspar.com | Website for students | VTU NOTES
SCHEMA DESCRIPTION:
AUTHOR
AUTHOR_ID NAME CITY COUNTRY
PUBLISHER
PUBLISHER_ID NAME CITY COUNTRY
CATALOG
BOOK_ID TITLE AUTHOR_ID PUBLISHER_ID CATEGORY_ID YEAR PRICE
------------------ --------------------- --------------------
CATEGORY
` CATEGORY_ID DESCRIPTION
ORDER_DETAILS
ORDER_NO BOOK_ID QUANTITY
35 www.bookspar.com
www.bookspar.com | Website for students | VTU NOTES
ER DIAGRAM:
PUBLISHER_ID
ANAME PNAM
E
TEXT
AUTHOR_ID ACITY
PCITY
AUTHOR
PCOUNTR
Y
PUBLISHES
ACOUNTRY
WRITE CATEGORY_ID
S
ORDER_N
O CATEGORY
QTY
DESC
ORDER_DETAILS
BELONGS_T
CONTAIN O
S
CATALOG
BOOK_ID PRICE
36
YEAR www.bookspar.com
TITLE
www.bookspar.com | Website for students | VTU NOTES
TABLE CREATION
Table created.
TABLE DESCRIPTION
INSERTING TUPLES
1 row created.
37 www.bookspar.com
www.bookspar.com | Website for students | VTU NOTES
TABLE CREATION
Table created.
TABLE DESCRIPTION
INSERTING TUPLES
1 row created.
38 www.bookspar.com
www.bookspar.com | Website for students | VTU NOTES
TABLE CREATION
Table created.
TABLE DESCRIPTION
INSERTING TUPLES
1 row created.
SQL> insert into category values ('32','os')
SQL> insert into category values ('33','dbms')
SQL> insert into category values ('34','gt')
SQL> insert into category values ('35','oops')
CATID DES
-----------------------------------
31 sys s/w
32 os
33 dbms
34 gt
35 oops
39 www.bookspar.com
www.bookspar.com | Website for students | VTU NOTES
TABLE CREATION
Table created.
TABLE DESCRIPTION
INSERTING TUPLES
1 row created.
40 www.bookspar.com
www.bookspar.com | Website for students | VTU NOTES
TABLE CREATION
Table created.
TABLE DESCRIPTION
INSERTING TUPLES
1 row created.
41 www.bookspar.com
www.bookspar.com | Website for students | VTU NOTES
93 43 150
94 43 25
95 45 160
QUERIES
1. 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.
RESULT
EXPLANATION
The nested query determines the average of all the book prices present in the catalog. Then the
two tables author and catalog are joined. The tuples with year greater than 2000 and the price
greater than the average are selected.
42 www.bookspar.com
www.bookspar.com | Website for students | VTU NOTES
RESULT
NAME
----------
ccc
EXPLANATION
The nested query selects the maximum value of quantity in the attribute quantity in table
order_details. Then the two tables catalog and order_details are joined. The tuple with the
maximum value of quantity is selected and the name of the author is displayed.
RESULT
EXPLANATION
The nested query selects all the tuples with the publisher name as explicitly given by the
user.Then using the update command,the price is incremented by 10% in these tuples.
43 www.bookspar.com
www.bookspar.com | Website for students | VTU NOTES
PROBLEM 5
PROBLEM STATEMENT:
iii) Find all the customers who have atleast 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.
vii) Create suitable front end for querying and displaying the results.
44 www.bookspar.com
www.bookspar.com | Website for students | VTU NOTES
SCHEMA DESCRIPTION:
BRANCH
BRANCH_NAME BRANCH_CITY ASSETS
ACCOUNT
ACC_NO BRANCH_NAME BALANCE
DEPOSITOR
CUSTOMER_NAME ACCNO
--------------------------- -----------
CUSTOMER
CUSTOMER_NAME CUSTOMER_STREET CUSTOMER_CITY
LOAN
BORROWER
CUSTOMER_NAME LOAN_NO
---------------------------- ---------------
45 www.bookspar.com
www.bookspar.com | Website for students | VTU NOTES
ER DIAGRAM:
CITY LNO
BNAME GIVES
OUT LNAME
BRANCH LOAN
ASSETS
MANAGE BORROW
S S
CNAME
CSTREET
AACCN
O
ACCOUNT CUSTOMER
CCITY
BALANCE
DEPOSITS
NAME ACCNO
46 www.bookspar.com
www.bookspar.com | Website for students | VTU NOTES
TABLE CREATION
Table created.
TABLE DESCRIPTION
INSERTING TUPLES
TABLE CREATION
47 www.bookspar.com
www.bookspar.com | Website for students | VTU NOTES
(
accno int primary key,
branch_name varchar(25) not null,
balance decimal(10,2) not null,
foreign key(branch_name) references branch(branch_name)
);
Table created.
TABLE DESCRIPTION
INSERTING TUPLES
TABLE CREATION
Table created.
48 www.bookspar.com
www.bookspar.com | Website for students | VTU NOTES
TABLE DESCRIPTION
TABLE CREATION
Table created.
TABLE DESCRIPTION
INSERTING TUPLES
49 www.bookspar.com
www.bookspar.com | Website for students | VTU NOTES
CUSTOMER_NAME ACCNO
--------------------------------------------------
ramu 123
ramu 156
ramu 189
kumar 456
john 789
mike 478
sachin 778
TABLE CREATION
Table created.
TABLE DESCRIPTION
INSERTING TUPLES
50 www.bookspar.com
www.bookspar.com | Website for students | VTU NOTES
Table created.
TABLE DESCRIPTION
INSERTING TUPLES
CUSTOMER_NAME LOAN_NUMBER
-------------------------------------------------------------
ramu 1111
kumar 2222
john 3333
mike 4444
sachin 5555
QUERIES
1. Find all the customers who have atleast two accounts at the Main branch.
51 www.bookspar.com
www.bookspar.com | Website for students | VTU NOTES
CUSTOMER_NAME COUNT(*)
------------------------------------------------------
ramu 2
EXPLANATION
2. Find all the customers who have an account at all the branches located in a
specific city.
RESULT
CUSTOMER_NAME
-------------------------
ramu
EXPLANATION
The inner query counts the number of branches in bangalore which is used to compare with the
number of branches in Bangalore in which a customer has accounts. We join the account,
depositor and branch tables by specifying the appropriate join conditions and selecting only those
tuples having branches in Bangalore grouped by the customer name.
52 www.bookspar.com
www.bookspar.com | Website for students | VTU NOTES
3. Demonstrate how you delete all account tuples at every branch located in a
specific city.
CUSTOMER_NAME ACCNO
------------------------------------------------
ramu 123
ramu 156
ramu 189
kumar 456
mike 478
EXPLANATION
The nested query selects the tuples that satisfy the selection condition branch_city = delhi from
the relation branch .The IN operator compares the subtuple of value branch_name for each tuple
in account relation with the tuples produced by the nested query. Finally, the selected tuples are
deleted from the account relation. Here the account tuples containing the branches in delhi, i.e, in
noida and green park are deleted. Also, since depositor references the accno from the account
relation, for the accno deleted from the account table, corresponding tuples containing the same
accno in depositor relation are deleted.
53 www.bookspar.com