Anda di halaman 1dari 19

This is to certify that Mr. /Ms. Karthik.

k has satisfactorily completed the course of


Database Management lab prescribed by the University VTU course in the
Laboratory of this college in the year 2009-10.

Name of the candidate: Karthik.k


Register No. 1JB07CS037
Date of Practical Examination:

Signature of Teacher in-charge

Marks

Maximum Obtained

25 Head of the Department

1. Design an “INSURANCE” database with the following tables and


execute related Queries:
TABLE DESCRIPTION (SCHEMA DESIGN)
1)
PERSON(Driver_Id:String,Driver_Name:String,Driver_Address:String)
2) CAR(Reg_No:String,Model:String,Year:Int)
3)ACCIDENT(Report_No:Int,Accident_Date:DATE,Acc
ident_Location:String)
4) OWNS(Driver_Id#:String,Reg_No:String)
5)
PARTICIPATED(Driver_Id:String,Reg_No:string,Report_No:Int,
Damage_Amt:Int)
QUERY:-
1. Create the above tables by properly specifying the primary keys and the
foreign keys.
2.Enter atleast five tuples for each relation.
3.Demonstrate how your
1)Update the damage amount for the car with a specific Regno in the accident with report
number 12 to 25000.
2) Add a new accident to the database.
4. Find the total number of people who owned cars belonging to a specific
model were involved in accident in 2002.
5. Find the number of accidents in which cars belonging to a specific model
were involved.
Step1: Creating Tables
SQL>create table PERSON (Driver_Id VARCHAR2(6),Driver_Name
VARCHAR2(15),Driver_Address VARCHAR2(20),PRIMARY KEY (Driver_Id));
Table created.

SQL>create table CAR (Reg_No VARCHAR2(6) PRIMARY KEY, Model


VARCHAR2(10),Year NUMBER(4));
Table created.

SQL>create table ACCIDENT (Report_No NUMBER(4), Accident_Date DATE,


Accident_Location VARCHAR2(15),PRIMARY KEY (Report_No));
Table created.

SQL>create table OWNS (Driver_Id VARCHAR2(6),Reg_No


VARCHAR2(6),PRIMARY KEY (Driver_Id),FOREIGN KEY (Driver_Id)
REFERENCES PERSON,FOREIGN KEY (Reg_No) REFERENCES CAR);
Table created.

SQL>create table PARTICIPATED (Driver_Id VARCHAR2(6),Reg_No


VARCHAR2(6), Report_No NUMBER(4),Damage_Amt NUMBER(8,2),PRIMARY
KEY (Driver_Id, Reg_No, Report_No),FOREIGN KEY (Driver_Id) REFERENCES
PERSON,FOREIGN
KEY (Reg_No) REFERENCES CAR,FOREIGN KEY (Report_No) REFERENCES
ACCIDENT);
Table created.

Step2:Inserting Values
SQL> insert into PERSON values ('D00001','Ravi','Bangalore');
1 row created.

SQL> insert into PERSON values ('D00002’,’Satish’,’Chennai’);


1 row created.

SQL> insert into PERSON values ('D00003’,’Harish’,’Mumbai’);


1 row created.

SQL> insert into PERSON values ('D00004’,’Ramesh’,’Bangalore’);


1 row created.
SQL> insert into PERSON values ('D00005’,’Kamesh’,’Hyderabad’);
1 row created.

SQL> insert into CAR values(‘KAR123 ‘,’Mercedes’,2000);


1 row created.

SQL> insert into CAR values(‘TM200’,’ Santro’,2001);


1 row created.

SQL> insert into CAR values(‘MH126 ‘,’Civic’,2006);


1 row created.

SQL> insert into CAR values(‘KAR234’,’Fabia’ ,2008);


1 row created.

SQL> insert into CAR values(‘AP456’,’Quallis’,2004);


1 row created.

SQL>insert into ACCIDENT values(12,’24-MAY-00’,’ Kengeri’);


1 row created.

SQL> insert into ACCIDENT values(40,’ 17-OCT-02’,’ Coimbatore’);


1 row created

SQL> insert into ACCIDENT values(39 ,’12-MAR-07’,’ Matunga’);


1 row created.

SQL> insert into ACCIDENT values(102 ,’25-JUL-08’,’ Banshankri’);


1 row created.

SQL> insert into ACCIDENT values(47 ,’09-AUG-05’,’ Sickandrabad’);


1 row created.

SQL>insert into OWNS values(‘D00001’,’ KAR123’);


1 row created.

SQL>insert into OWNS values(‘D00002’,’ TM200’);


1 row created.

SQL>insert into OWNS values(‘D00003’,’ MH126’);


1 row created.

SQL>insert into OWNS values(‘D00004’,’ KAR234’);


1 row created.

SQL>insert into OWNS values(‘D00005’,’ AP456’);


1 row created.

SQL>insert into PARTICIPATED values(‘D00001’,’ KAR123’, 12, 25000);


1 row created.

SQL>insert into PARTICIPATED values(‘D00002’,’ TM200’,40,1000);


1 row created.

SQL>insert into PARTICIPATED values(‘D00003 ‘,’MH126’,39,12000);


1 row created.

SQL>insert into PARTICIPATED values(‘D00004 ‘,’KAR234’,10,22000);


1 row created.

SQL>insert into PARTICIPATED values(‘D00005’ ,’AP456’,47,6000);


1 row created.

Step3:Queries

1.Query To Update The Participated Table :

SQL>update PARTICIPATED set Damage_Amt=25000 WHERE Report_No=12 ;


1 row updated.

2.Add a new accident to database:

SQL>insert into ACCIDENT values(27,’20-MAY-09’,’Bhopal’);


1 row created.

3. Find Out The Total Number Of People Who Owned Cars That Were Involved In
accident In 2002:

SQL>select COUNT(*) from accident where ACCIDENT_DATE like '%08';

4. Find The number Of Accidents In Which Cars Belonging To A Specific Type Is


Involved :

SQL> select COUNT(*) from CAR,PARTICIPATED where


CAR.Reg_No=PARTICIPATED.Reg_No AND Model='Mercedes';
2. Design an “ORDER PROCESSING” database in a company with the
following tables and execute related Queries:
TABLE DESCRIPTION (SCHEMA DESIGN)
1)
CUSTOMER(Customer_No:Int,Customer_Name:String,
City:String)

2)ORDERS(Order_No:Int,Odate:DATE,Customer_No:Int,Order_Amt:Int
)
3) ORDER_ITEM(Order_No:Int,Item_No:Int,Qty:Int)
4) ITEM(Item_No:Int,Unit_Price:Int)
5)
SHIPMENT(Order_No:Int,Warehouse_No:Int,Ship_Date:DATE)
6) WAREHOUSE(Warehouse_No:Int,City:String)

QUERY:-
1) Create the above tables by properly specifying the primary keys and the foreign
keys.
2) Enter at least five tuples for each relation.
3) Produce a listing CUSTNAME,#oforders,AVG_ORDER_AMT, where the middle
column is the total numbers of orders by the customer and the last column is the
average order amount for that customer.
4) List the order# for orders that were shipped from all the warehouse that the
company has
in a specific city.
5) Demonstrate how you delete item# 10 from the ITEM table and make that field
null in the
ORDER_ITEM table.
Step1:Creating tables
SQL>create table CUSTOMER(Customer_No NUMBER(4) PRIMARY KEY,
Customer_Name VARCHAR2(15),City VARCHAR2(15));
Table created.

SQL>create table ORDERS(Order_No NUMBER(4),Odate DATE, Customer_No


NUMBER(4),Order_Amt NUMBER(6),PRIMARY KEY(Order_No),FOREIGN
KEY(Customer_No) REFERENCES CUSTOMER);
Table created.

SQL>create table ITEM(Item_No NUMBER(4),Unit_Price NUMBER(6),PRIMARY


KEY(Item_No));
Table created.

SQL>create table ORDER_ITEM(Order_No NUMBER(4) PRIMARY KEY, Item_No


NUMBER(4),Qty NUMBER(4),FOREIGN KEY(Order_No) REFERENCES
ORDERS,FOREIGN KEY(Item_No) references ITEM on delete set null);
Table created.

SQL>create table WAREHOUSE(Warehouse_No NUMBER(4),City


VARCHAR2(10),PRIMARY KEY(Warehouse_No));
Table created.

SQL>create table SHIPMENT(Order_No NUMBER(4) PRIMARY KEY,Warehouse_No


NUMBER(4),Ship_Date DATE, FOREIGN KEY(Order_No) REFERENCES ORDERS,
FOREIGN KEY(Warehouse_No) REFERENCES WAREHOUSE);
Table created.

Step2: Inserting values

SQL> insert into CUSTOMER values(0001,'Harish','Bangalore');


1 row created.

SQL> insert into CUSTOMER values(0002,'Surjeet','Delhi');


1 row created.
SQL> insert into CUSTOMER values(0003,'Sarkar','Mumbai');
1 row created.

SQL> insert into CUSTOMER values(0004,'King','Hyderabad');


1 row created.

SQL> insert into CUSTOMER values(0005,'Raja','Bangalore');


1 row created.

SQL> insert into ORDERS values(1,'23-MAY-00',0001,10000);


1 row created.

SQL> insert into ORDERS values(2,'25-JUN-00',0002,24000);


1 row created.

SQL> insert into ORDERS values(7,'20-JAN-01',0003,20000);


1 row created.

SQL> insert into ORDERS values(15,'10-DEC-02',0004,30000);


1 row created.

SQL> insert into ORDERS values(20,'17-JUL-03',0005,20000);


1 row created.

SQL> insert into ITEM values(100,5000);


1 row created.

SQL> insert into ITEM values(102,8000);


1 row created.

SQL> insert into ITEM values(104,10000);


1 row created.

SQL> insert into ITEM values(110,15000);


1 row created.

SQL> insert into ITEM values(120,20000);


1 row created.

SQL> insert into ORDER_ITEM values(1,100,2);


1 row created.

SQL> insert into ORDER_ITEM values(2,102,3);


1 row created.

SQL> insert into ORDER_ITEM values(7,104,2);


1 row created.

SQL> insert into ORDER_ITEM values(15,110,2);


1 row created.

SQL> insert into ORDER_ITEM values(20,120,1);


1 row created.

SQL> insert into WAREHOUSE values(1,'Bangalore');


1 row created.

SQL> insert into WAREHOUSE values(2,'Delhi');


1 row created.

SQL> insert into WAREHOUSE values(3,'Mumbai');


1 row created.

SQL> insert into WAREHOUSE values(4,'Hyderabad');


1 row created.

SQL> insert into WAREHOUSE values(5,'Mangalore');


1 row created.

SQL> insert into SHIPMENT values(1,1,'24-JUN-00');


1 row created.

SQL> insert into SHIPMENT values(2,2,'17-SEP-00');


1 row created.

SQL> insert into SHIPMENT values(7,3,'17-MAR-01');


1 row created.

SQL> insert into SHIPMENT values(15,4,'19-JAN-03');


1 row created.

SQL> insert into SHIPMENT values(20,5,'28-AUG-03');


1 row created.
STEP3: Queries

1. Produce a listing CUSTNAME,No_of_orders,AVG_ORDER_AMT, where the middle


column is the total numbers of orders by the customer and the last column is the
average order amount for that customer.

SQL>select Customer_Name AS CUSTNAME,COUNT(Order_No) AS


No_of_orders,AVG(Order_Amt) AS AVG
from CUSTOMER C,ORDERS O
where C.Customer_No=O.Customer_No
Group By Customer_Name;

2. List the order# for orders that were shipped from all the warehouses that the
company has in a specific city.

SQL>select Order_No
from WAREHOUSE W,SHIPMENT S
where W.Warehouse_No=S.Warehouse_No AND City=’Bangalore’;

3. Demonstrate how you delete item# 10 from the ITEM table and make that field
null in the ORDER_ITEM table.

SQL>delete from ITEM where Item_No=102;


3.Design a “STUDENT ENROLLMENT” database with the following
tables and execute related Queries:
TABLE DESCRIPTION (SCHEMA DESIGN)
1)STUDENT(Reg_no:String, Name:String,
Major:String,Bdate:DATE)

2)COURSE(Course_No:Int,Cname:String,Dept:String)

3)ENROLL(Reg_no:String,Course_No:Int,Sem:int,Marks:Int)

4)BOOK_ADOPTION(Course_No:Int,Sem:Int,Book_ISBN:Int)

5)TEXT(Book_ISBN:Int,Book_Title:String,Publisher:String,Autho:Strin
g)QUERY:-
1) Create the above tables by properly specifying the primary keys and the foreign
keys.
2) Enter at least five tuples for each relation.
3) Demonstrate how you add a new text book to the database and make this book
be adopted by some department.
4) 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.
5) List any department that has all its adopted books published by a specific
publisher.
STEP1:Creating tables

SQL> create table STUDENT(Reg_No VARCHAR2(10) PRIMARY KEY,Name


VARCHAR2(15),Major VARCHAR2(15),Bdate DATE);
Table created.

SQL> create table COURSE(Course_No NUMBER PRIMARY KEY,Course_Name


VARCHAR2(25),Dept VARCHAR2(3));
Table created.

SQL> create table ENROLL(Reg_No VARCHAR2(10),Course_No NUMBER,Sem


NUMBER(1),Marks NUMBER(3),PRIMARY KEY(Reg_No,Course_No,Sem),FOREIGN
KEY(Reg_No) references STUDENT,FOREIGN KEY(Course_No) references COURSE);
Table created.

SQL> create table TEXT(Book_ISBN NUMBER PRIMARY KEY,Book_Title


VARCHAR2(50),Publisher VARCHAR2(25),Author VARCHAR2(25));
Table created.

SQL> create table Book_Adoption(Course_No NUMBER,Sem NUMBER(1),Book_ISBN


NUMBER,PRIMARY KEY(Course_No,Sem),FOREIGN KEY(Course_No) references
COURSE,FOREIGN KEY(Book_ISBN) references TEXT);
Table created.

Step2:Inserting values

SQL> insert into STUDENT values('1JB07CS037','Karthik.k','CS','24-MAY-1990');


1 row created.

SQL> insert into STUDENT values('1JB07CS006','Amith Kamath','CS','22-SEP-1989');


1 row created.

SQL> insert into STUDENT values('1JB07CS024','Charan','CS','27-SEP-1988');


1 row created.

SQL> insert into STUDENT values('1JB07CS007','Amit Ram','CS','18-SEP-1989');


1 row created.

SQL> insert into STUDENT values('1JB07CS039','Kavitha Raj','CS','1-JUL-1989');


1 row created.

SQL> insert into COURSE values(301,'Data structures in C','CSE');


1 row created.

SQL> insert into COURSE values(401,'OOPS with C++','CSE');


1 row created.

SQL> insert into COURSE values(501,'DBMS','CSE');


1 row created.

SQL> insert into COURSE values(502,'System Software','CSE');


1 row created.

SQL> insert into COURSE values(101,'Engineering Maths1','Mat');


1 row created.

SQL> insert into ENROLL values('1JB07CS037',301,3,125);


1 row created.

SQL> insert into ENROLL values('1JB07CS006',401,4,125);


1 row created.

SQL> insert into ENROLL values('1JB07CS039',501,5,125);


1 row created.

SQL> insert into ENROLL values('1JB07CS022',101,1,125);


1 row created.

SQL> insert into ENROLL values('1JB07CS007',401,4,125);


1 row created.

SQL> insert into TEXT values(1000,'DBMS','Pearson Education','Navathe');


1 row created.

SQL> insert into TEXT values(2000,'System Software','Pearson Education','Beck');


1 row created.

SQL> insert into TEXT values(900,'Engineering


Maths1','United','K.S.Chandreshekariah');
1 row created.
SQL> insert into TEXT values(1050,'OOPS with C++','Oxford Education','Sourav
Sahay');
1 row created.

SQL> insert into TEXT values(800,'Data structures in C','Independent','Padma


Reddy');
1 row created.

SQL> insert into BOOK_ADOPTION values(301,3,800);


1 row created.

SQL> insert into BOOK_ADOPTION values(401,4,1050);


1 row created.

SQL> insert into BOOK_ADOPTION values(501,5,1000);


1 row created.

SQL> insert into BOOK_ADOPTION values(101,1,900);


1 row created.

SQL> insert into BOOK_ADOPTION values(502,5,2000);


1 row created.

Step3:Queries
4. Design a “BOOK DEALER” database with the following tables and
execute related Queries:
TABLE DESCRIPTION(SCHEMA DESIGN)
1)
AUTHOR(Author_Id:Int,Name:String,City:String,Country:String)
2)
PUBLISHER(Publisher_Id:Int,Name:String,City:String,Country:String)
3)
CATALOG(Book_id:Int,Title:String,Author_Id:Int,Publ
isher_Id:Int,
Category_Id:Int,Year:Int,Price:Int).
4) CATEGORY(Category_Id:Int, Description:String).
5)
ORDER_DETAILS(Order_no:Int,Book_Id:Int,Quantity:Int).
QUERY:-
1) Create the above tables by properly specifying the primary keys and the foreign
keys.
2) Enter atleast five tuples for each relation.
3) 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.
4) Find the author of the book which has maximum sales.
5) Demonstrate how you increase the price of books published by a specific
publisher by 10%.
STEP1:Creating tables

SQL> create table AUTHOR(Author_Id NUMBER PRIMARY KEY, Name


VARCHAR2(15),City VARCHAR2(20),Country VARCHAR2(20));
Table created.

QL> create table PUBLISHER(Publisher_Id NUMBER PRIMARY KEY, Name


VARCHAR2(15),City VARCHAR2(20),Country VARCHAR2(20));
Table created.

SQL> create table CATEGORY(Category_Id NUMBER PRIMARY KEY, Description


VARCHAR2(20));
Table created.

SQL> create table CATALOG(Book_Id NUMBER, Title VARCHAR2(20),Author_Id


NUMBER, Publisher_Id NUMBER, Category_Id NUMBER, Year NUMBER(4),Price
NUMBER,PRIMARY KEY(Book_Id),FOREIGN KEY(Author_Id) references
AUTHOR,FOREIGN KEY(Publisher_Id)references PUBLISHER,FOREIGN
KEY(Category_Id)references CATEGORY);
Table created.

SQL> create table ORDER_DETAILS(Order_No NUMBER, Book_Id NUMBER,Qty


NUMBER,PRIMARY KEY(Order_No, Book_Id));
Table created.

Step2:Inserting values

SQL> insert into AUTHOR values(1,'Arundathi Roy','Kolkata','India');


1 row created.

SQL> insert into AUTHOR values(2,'Shobha de','Mumbai','India');


1 row created.

SQL> insert into AUTHOR values(3,'Conan Doyle','London','Britain');


1 row created.

SQL> insert into AUTHOR values(4,'Alfred Hitch','London','Britain');


1 row created.

SQL> insert into AUTHOR values(5,'Taslima Nasreen','Dhaka','Bangladesh');


1 row created.

SQL> insert into PUBLISHER values(1,'Wrigs','London','Britain');


1 row created.

SQL> insert into PUBLISHER values(2,'Wrox','London','Britain');


1 row created.

SQL> insert into PUBLISHER values(3,'Mc-Graw','London','Britain');


1 row created.

SQL> insert into PUBLISHER values(4,'Bharti','Mumbai','India');


1 row created.

SQL> insert into PUBLISHER values(5,'BPB','Delhi','India');


1 row created.

SQL> insert into CATEGORY values(1,'Thriller');


1 row created.

SQL> insert into CATEGORY values(2,'Thriller');


1 row created.

SQL> insert into CATEGORY values(3,'Love Story');


1 row created.

SQL> insert into CATEGORY values(4,'Mystery');


1 row created.

SQL> insert into CATEGORY values(5,'Social Fiction');


1 row created.
SQL> insert into CATALOG values(1,'God of Small Things',1,4,3,2001,200);
1 row created.

SQL> insert into CATALOG values(2,'India Discovered',1,5,5,2002,3000);


1 row created.

SQL> insert into CATALOG values(3,'The Blue Carbuncle',3,3,1,2000,300);


1 row created.

SQL> insert into CATALOG values(4,'Gloomy Days',3,2,1,2002,3000);


1 row created.

SQL> insert into CATALOG values(5,'Battle of Horses',1,4,1,2002,3000);


1 row created.

SQL> insert into ORDER_DETAILS values(1,1,1);


1 row created.

SQL> insert into ORDER_DETAILS values(2,2,2);


1 row created.

SQL> insert into ORDER_DETAILS values(3,3,5);


1 row created.

SQL> insert into ORDER_DETAILS values(4,4,10);


1 row created.

SQL> insert into ORDER_DETAILS values(5,5,1);


1 row created.

Step3:Queries
5. Design a “BANKING ENTERPRISE” database with the following
tables and execute related Queries:
TABLE DESCRIPTION (SCHEMA DESIGN)
1) BRANCH (Branch_Name: String, Branch_city:
String, Assets: Real).
2) ACCOUNT (Acc_no: Int, Branch_Name: String,
Balance: Real).
3) DEPOSITOR (Customer_Name: String, Acc_no:
int).
4) CUSTOMER (Customer_Name: String,
Customer_Street: String,
Customer_City: string).
5) LOAN (Loan_no: Int, Branch_Name: String,
Amount: Real).
6) BORROWER (Customer_Name: string, Loan_No:
Int).

QUERY:-
1) Create the above tables by properly specifying the primary keys and the foreign
keys.
2) Enter atleast five tuples for each relation
3) Find all the customers who have atleast two accounts at the Main Branch.
4) Find all the customers who have an account at all the branches located in a
specific city.
5) Demonstrate how you delete all account tuples at every branch located in a
specific city

Anda mungkin juga menyukai