Beruflich Dokumente
Kultur Dokumente
I. INSURANCE DATABASE
1.
SQL> create table person (driver_id varchar(10) primary key, name varchar(10),
address varchar(20));
Table created.
2.
SQL> create table car (regno varchar(10) primary key, model varchar(10),year
number(4));
Table created.
3.
SQL> create table accident (report_no number (10) primary key, adate date, location
varchar(15));
Table created.
4.
SQL> create table owns (driver_id varchar(10), regno varchar(10),
2primary key(driver_id,regno),
3 foreign key(driver_id) references person(driver_id),
4 foreign key(regno) references car);
Table created.
DRIVER_ID REGNO
---------------- ---------
Database Lab Page 3 of 23
001 ka01
002 ka02
003 ka03
004 ka04
005 ka05
5.
SQL> create table participated (driver_id varchar(10),regno varchar(10),
2 report_no number(10), dam_amt number(7,2),
3 primary key(driver_id,regno,report_no),
4 foreign key(driver_id) references person,
5 foreign key(regno) references car,
6 foreign key(report_no) references accident);
Table created.
Queries
1. (a) Update the damage_amt for the car with specific reg_no in the accident with
report_no 12 to 25000.
2. Find the total number of the people who owned cars that are involved in
accident in 2004.
No_of people
----------------
4
3. Find the number of the accidents in which cars belonging to a specific model
were involved.
SQL> select count(*) as "No.of Accidents" from accident where report_no in (select
report_no from participated where regno in (select regno from car where
model='ford'));
No.of Accidents
Database Lab Page 5 of 23
---------------
2
Database Lab Page 6 of 23
1.
SQL> create table customer(custno number(3) primary key,
2 name varchar(10),city varchar(10));
Table created.
2.
SQL> create table order1 (orderno number(4) primary key,date1 date, custno
number(3),ord_amt number(7,2));
Table created.
3.
SQL> create table item (itemno number (4) primary key, unit_price number(7,2));
Table created.
ITEMNO UNIT_PRICE
--------- -------------------
201 500
202 600
203 700
204 800
205 100
4.
SQL> create table order_item(orderno number(4),itemno number(4), qty number(3),
Database Lab Page 8 of 23
12 112 11-JAN-07
13 113 12-JAN-07
14 114 13-JAN-07
15 115 14-JAN-07
11 112
6.
SQL> create table warehouse (warehouseno number(3) primary key, city
varchar(20));
SQL> insert into warehouse values (111,'bangalore')
1 row created.
WAREHOUSENO CITY
----------- ----------- ---------
111 bangalore
112 bijapur
113 bellary
114 gadag
115 mumbai
Queries
1. Produce a listing, Customer name, number of orders and avg_Order_amt, for
that customer.
ORDERNO
---------------
11
Create tables STUDENT ( reg_no : String, name : String, major : String, bdate : date )
COURSE ( course : int, cname : String, dept : string )
ENROLL ( reg_no : String, course : int, sem : int, marks : int )
BOOK_ADOPTION ( course : int, sem : int, ISBN : int )
TEXT ( book_ISBN : int, title : String, publisher : String );
1.
SQL> create table student(regno varchar(5) primary key,name varchar(10),
2 major varchar(5),bdate date);
2.
SQL> create table course (courseno number(2) primary key,cname varchar(5),dept
varchar(5));
3.
SQL> create table enroll(regno varchar(5) references student(regno),courseno
number(3) references course(courseno),sem number(2),marks number(3));
4.
SQL> create table text(book_isbn number(4) primary key,title varchar(10),publisher
varchar(10),author varchar(10));
5.
SQL> create table book_adoption(courseno number(3) references course, sem
number(3),
2 isbn number(4) references text));
Queries
1 row created.
No rows selected
3. List any dept that has all its adopted books published by a specific publisher.
DEPT
--------------------
ug
Database Lab Page 15 of 23
Create tables AUTHOR ( author_id : int, name : String, city : String, country : String )
PUBLISHER ( pub_id : int, name : String, city : String, country : String )
CATALOG ( book_id : int, title : String , author_id : int, pub_id :int ,
category_id : int, year : int, price : int )
CATEGORY ( category_id : int, description : String )
ORDER_DETAILS ( order_no : int, book_id : int, qty : int );
1.
SQL> create table author (author_id number(6) primary key, name varchar(10),city
varchar(10), country varchar(10));
Table created.
2.
SQL>create table publisher (publisher_id number (6) primary key, name varchar(10),
city varchar(10), country varchar(10));
3.
SQL>create table category (category_id number(4) primary key, description
varchar(10));
4.
SQL>create table catalog (book_id number(6) primary key, title varchar(10),
Author_id number(6) references author,
Publisher_id number(6) refences publisher,
Category_id number(4) references category,
Year number(4), price number(7,2));
5.
SQL>create table order_details (order_no number(6),book_id number(6),
qty number(3),
Primary key (order_no,book_id));
7 rows selected.
Queries
Database Lab Page 18 of 23
1. Give the details of author who have 2 or more books in the catalog and the price
of the books greater than average price of book in the catalog and year of
publication is after 2000.
SQL> select * from author where author_id = (select author_id from catalog
2 where book_id = (select book_id from order_details group by book_id
3 having sum(quantitiy)=(select max(sum(quantitiy)) from order_details
4 group by book_id)))
5 ;
AUTHOR_ID NAME CITY COUNTRY
--------- ---------- ---------- ---------- ---------------
104 A4 London england
1.
SQL> create table branch(branch_name varchar(20) primary key,branch_city
varchar(20),assets number(10,2));
Table created.
2.
SQL> create table account (accno number(3) primary key,branch_name varchar(20)
references branch,bal number(10,2));
Table created.
3.
SQL> create table customer(customer_name varchar(10) primary
key,customer_street varchar(20),customer_city varchar(20));
Table created.
4.
SQL>create table depositor (customer_name varchar(10) references customer, accno
number(3) references account);
Table created.
CUSTOMER_NAME ACCNO
-------------------------- ----------
Database Lab Page 21 of 23
c1 101
c1 102
c2 103
c4 104
c2 105
5.
SQL>create table loan(loan_number number(6) primary key, brnch_name
vrachar(20) references branch,amount number(10,2));
Table created.
6.
SQL>create table borrower (customer_name varchar(10) references customer,
loan_number number(3) refernces loan);
Table created.
CUSTOMER_NAME LOAN_NUMBER
-------------------------- ----------------------
c1 1
Database Lab Page 22 of 23
c2 3
c1 3
c4 4
c5 5
Queries
1.Find all the customers who have atleast two account in the main branch.
(assuming mainbranch=b1)
CUSTOMER_NAME
--------------------------
c1
2.Find the entire customers who have an account at all the branches in specific
city.
CUSTOMER_NAME
--------------------------
c1
3. Demonstrate how you delete all account tuples at every branch located in a
specific city.