Sei sulla pagina 1di 8

DATA BASE MANAGEMENT SYSTEMS LAB PROGRAMMING 1.

STUDENT DETAILS DATABASE :The student details database has a table with the following attributes. The primary keys are underlined
STUDENT (RegNo : number, Name : text, DOB : date , Marks : number)

create table STUDENT(REGNO int,NAME varchar2(15), DOB date,MARKS number(3));


a) Remove the existing attribute marks from the table alter table STUDENT DROP column MARKS; b) Change the data type of regno from integer to string. alter table STUDENT MODIFY REGNO varchar2(10); c) Add a new attribute PhoneNo to the existing table. alter table STUDENT ADD PHONENO int; d) Enter 5 tuples into the table. insert into STUDENT values(&REGNO,&NAME,&DOB,&PHONENO); e) Display all the tuples in student table. select * from STUDENT; f) Display all the students who were born in 1980s. select *from STUDENT where DOB between 01-jan-1980 and 30-dec-1980; g)Display all the students in alphabetical order of their names. Select *from STUDENT ORDER BY NAME;

2.

LIBRARY DATABASE :A library database has a table with the following attributes:
LIBRARY (BookId : number, Title : text, Author : text, Publisher : text, Year_Pub : number, Price : number ( 6,2) )

create table LIBRARY(BOOKID int, TITLE varchar2(10), AUTHOR varchar2(15), PUBLISHER varchar2(15), YEAR_PUB int, PRICE dec(6,2));
a) Enter 5 tuples into the table. insert into LIBRARY values (&BOOKID, &TITLE, &AUTHOR, &PUBLISHER, &YEAR_PUB, &PRICE); b) Display the different publishers from the list. select DISTINCT PUBLISHER from the LIBRARY; c) Arrange the tuples in the alphabetical order of book titles.

select * from LIBRARY ORDER BY TITLE; d) List details of all the books whose price ranges between Rs. 100.00 and Rs. 300.00 select *from LIBRARY where PRICE between 100.00 and 300.00; e)Display all the authors under a specific publisher. Select AUTHOR from LIBRARY where PUBLISHER=skyward;

3.

EMPLOYEE SALARY DATABASE :The salary database of an organization has a table with the following attributes :
EMPSALARY ( EmpCode :number, EmpName :text, DOB : date, Dept : text, Salary : number(10,2) ) Create table EMPSALARY(EMPCODE int, EMPNAME varchar2(15), DOB date, DEPT varchar2(15), SALARY dec(10,2)); a) Enter 5 tuples into the table. insert into EMPSALARY values(&EMPCODE,&EMPNAME,&DOB,&DEPT,&SALARY); b) Display the number of employees working in each department. Select DEPT, count(*) from EMPSALARY GROUP BY DEPT; c) Find the sum of the salaries of all employees. Select sum(SALARY) from EMPSALARY; d) Find the sum and average of the salaries of employees of a particular department. Select sum(SALARY), avg(SALARY) from EMPSALARY where DEPT=cs; e) Find the highest salary that an employee draws. Select max(SALARY) from EMPSALARY; f) Find the least salary that an employee draws. Select min(SALARY) from EMPSALARY; g) Find the total salary for each department. Select sum(SALARY) from EMPSALARY GROUP BY DEPT; h) Increase the salary of those employees working for the computer department by Rs. 1000. Update EMPSALARY set SALARY=SALARY+1000 where DEPT=cs; i)Display all employees increasing order of their age for a specific department. Select *from EMPSALARY ORDER BY DOB where DEPT=cs;

4. INVENTORY DATABASE :An inventory database has the following tables


ITEM (ItemCode : number, ItemName : text, Price : number(10,2) ) PURCHASE (ItemCode : number, Quantity : number) a) Create the tables with the above attributes.

Create table ITEM(ITEMCODE int primary key,ITEMNAME varchar2(15), PRICE dec(10,2)); Create table PURCHASE(ITEMCODE int primary key, QUANTITY int, foreign key (ITEMCODE) references ITEM(ITEMCODE));
b) Enter 5 7 tuples into the tables. Insert into ITEM values(&ITEMCODE,&ITEMNAME,&PRICE); Insert into PURCHASE values(&ITEMCODE,&QUANTITY); c) List the items purchased Select ITEMNAME from ITEM; d) Display the total items purchased ( listing must have the columns :ItemCode, ItemName, TotalQuantity) Select ITEM.ITEMCODE, ITEM.ITEMNAME, PURCHASE.QUANTITY from ITEM,PURCHASE where ITEM.ITEMCODE=PURCHASE.ITEMCODE; e) List the items which are not purchased by anyone. Select ITEM.ITEMNAME FROM ITEM WHERE ITEM.ITEMCODE NOT IN (select ITEMCODE from PURCHASE);

5. BANK CUSTOMER DATABASE :A bank customer database has two tables CUSTOMER and ACCOUNT.
CUSTOMER (CustNo: number, CustName : text, City : text, AccNo : number , Balance : number( 10,2)) ACCOUNT (AccNo: number, AccType: text, Branch : text, AccStatus : text, ChequeFacility : text) a) Create the above tables and specify the primary and foreign keys create table CUSTOMER(CUSTNO int, CUSTNAME varchar2(15), CITY varchar2(15), ACCNO int, BALANCE dec(10,2), primary key(CUSTNO,ACCNO)); create table ACCOUNT(ACCNO int, ACCTYPE varchar2(10), BRANCH varchar2(15), ACCSTATUS varchar2(10), CHEQUEFACILITY varchar2(10), primary key(ACCNO), foreign key (ACCNO) references CUSTOMER(ACCNO)); b) Enter 5 8 tuples for each relation insert into CUSTOMER values(&CUSTNO,&CUSTNAME,&CITY,&ACCNO, &BALANCE); insert into ACCOUNT values(&ACCNO,&ACCTYPE,&BRANCH, &ACCSTATUS, &CHEQUEFACILITY); c) List the customers from Bangalore who have cheque facility.

Select CUSTOMER.CUSTNAME from CUSTOMER,ACCOUNT where CITY=bangalore and CHEQUEFACILITY=yes and CUSTOMER.ACCNO=ACCOUNT.ACCNO; d) List all the customers whose balance is greater than 30000.00 and have an active account. Select CUSTOMER.CUSTNAME from CUSTOMER,ACCOUNT where BALANCE>30000.00 and ACCSTATUS=active and CUSTOMER.ACCNO = ACCOUNT.ACCNO; e) Find the current outstanding balance amount of branch Malleswaram select ACCOUNT.BRANCH, sum(CUSTOMER.BALANCE) from ACCOUNT, CUSTOMER where CUSTOMER.ACCNO=ACCOUNT.ACCNO AND ACCOUNT.BRANCH =Malleswaram;

6.

INSURANCE DATABASE :Consider the Insurance database given below. The primary keys are underlined and the data types are specified.
PERSON (DriverId: text, Name : text, Address : text) CAR (RegNo: text, Model: text, Year: number) OWNS (DriverId : text, RegNo: text) ACCIDENT (ReportNo: number, AccDate: Date, Location: text) PARTICIPATED (DriverId: text, RegNo: text, ReportNo: number, Dmg_Amt: number(10,2)) a. Create the above tables by specifying the primary and foreign keys. Create table PERSON(DRIVERID varchar2(10) primary key, NAME varchar2(15), ADDRESS varchar2(15)); Create table CAR(REGNO varchar2(10) primary key, MODEL varchar2(10),YEAR int); Create table OWNS(DRIVERID varchar2(10),REGNO varchar2(10), primary key(DRIVERID,REGNO), foreign key (DRIVERID) references PERSON(DRIVERID), foreign key (REGNO) references CAR(REGNO)); Create table ACCIDENT(REPORTNO int primary key, ACCDATE date, LOCATION varchar2(15)); Create table PARTICIPATED(DRIVERID varchar2(10),REGNO varchar2(10), REPORTNO int, DMG_AMT dec(10,2), primary key(DRIVERID,REGNO,REPORTNO), foreign key (DRIVERID) references PERSON(DRIVERID), foreign key (REGNO) references CAR(REGNO), foreign key (REPORTNO) references ACCIDENT(REPORTNO)); b. Enter atleast five tuples for each relation insert into PERSON values (&DRIVERID,&NAME,&ADDRESS); insert into CAR values (&REGNO,&MODEL,&YEAR); insert into OWNS values (&DRIVERID,&REGNO);

insert into ACCIDENT values (&REPORTNO,&ACCDATE,&LOCATION); insert into PARTICIPATED values (&DRIVERID,&REGNO,&REPORTNO,&DMG_AMT); c. i. Update the damage amount for each car accident. Update PARTICIPATED set DMG_AMT=DMG_AMT+2000 where REGNO between 2 and 6; ii. Add a new accident to the database. Insert into ACCIDENT values(10,5-APR-2000,KOLKATA); Insert into PARTICIPATED values(20, 2, 10, 189.75); d. Find the total number of people who owned cars that were involved in accidents in the year 2002. Select count(*) from ACCIDENT where ACCDATE between 01-jan-2002 and 30-dec-2002; e. Find the number of accidents in which cars belonging to a specific model were involved. Select count(*) from CAR, PARTICIPATED where MODEL=maruthi and CAR.REGNO=PARTICIPATED.REGNO; f. Display the owners and their car details.

Select PERSON.NAME, CAR.REGNO, CAR.MODEL, CAR.YEAR from PERSON,CAR where PERSON.DRIVERID=OWNS.DRIVERID and CAR.REGNO=OWNS.REGNO; 7. ORDER PROCESSING DATABASE :Consider the following relations for an order processing database application in a company.
CUSTOMER(CustId: number, CustName: text, City: text) CUSTORDER(OrderNo: number, OrderDate: date, CustId: number, OrderAmount: number) ITEM (ItemNo : number, ItemName: text, UnitPrice number(10,2)); ORDER_ITEM(OrderNo: number, ItemNo: number, OrdItemQty : number) WAREHOUSE(WareHohouseNo: number, City: text) SHIPMENT(OrderNo: number, WareHohouseNo: number, ShipDate: date) a. Create the above tables by properly specifying the primary keys and the foreign keys. Create table CUSTOMER(CUSTID int primary key, CUSTNAME varchar2(15),CITY varchar2(10)); Create table CUSTORDER(ORDERNO int, ORDERDATE date, CUSTID int, ORDERAMOUNT int, primary key (ORDERNO,CUSTID),

foreign key (CUSTID) references CUSTOMER(CUSTID)); Create table ITEM(ITEMNO int primary key, ITEMNAME varchar2(15), UNITPRICE dec(10,2)); Create table ORDER_ITEM(ORDERNO int, ITEMNO int, ORDITEMQTY int, primary key(ORDERNO,ITEMNO), foreign key (ORDERNO) references CUSTORDER(ORDERNO), foreign key (ITEMNO) references ITEM(ITEMNO)); Create table WAREHOUSE(WAREHOUSENO int primary key, CITY varchar2(10) ); Create table SHIPMENT(ORDERNO int, WAREHOUSENO int, SHIPDATE date, primary key (ORDERNO,WAREHOUSENO), foreign key (ORDERNO) references ORDERITEM(ORDERNO), foreign key (WAREHOUSENO) references WAREHOUSE(WAREHOUSENO)); b. Enter atleast five tuples for each relation. Insert into CUSTOMER values(&CUSTID,&CUSTNAME,&CITY); Insert into CUSTORDER values(&ORDERNO,&ORDERDATE, &CUSTID, &ORDERAMOUNT); Insert into ITEM values(&ITEMNO,&ITEMNAME,&UNITPRICE); Insert into ORDER_ITEM values(&ORDERNO,&ITEMNO,&ORDITEMQTY); Insert into WAREHOUSE values(&WAREHOUSENO,&CITY); Insert into SHIPMENT values(&ORDERNO,&WAREHOUSENO,&SHIPDATE); c. Produce a listing: CustName, no_of_orders,avg_order_amt, where the middle attribute is the total average order amount for that customer. Select CUSTOMER.CUSTID, count(CUSTORDER.ORDERNO), avg(CUSTORDER.ORDERAMOUNT) from CUSTOMER, CUSTORDER where CUSTOMER.CUSTID=CUSTORDER.CUSTID, group by CUSTOMER.CUSTID, CUSTOMER.CUSTNAME; d. List the order_no for orders that were shipped from all the warehouses that the company has in a specific way. Select count(SHIPMENT.ORDERNO) from SHIPMENT, WAREHOUSE where SHIPMENT.WAREHOUSENO=WAREHOUSE.WAREHOUSENO and CITY=delhi;

e. Demonstrate the delete of itemno 10 from the ITEM table and make that field null in the ORDER_ITEM table. (I) update ORDERITEM set ITEMNO=NULL where ITEMNO=11;

(II) delete from ITEM where ITEMNO=11; f.List all the items ordered by a particular customer. Select ITEM.ITEMNAME from ITEM, CUSTOMER where CUSTNAME=vijay;

8. STUDENT ENROLLMENT DATABASE :Consider the following database of students enrollment in courses and books adopted for each course. STUDENT(RegNo : number, Name : text, Major : text, BDate :date) COURSE(CourseNo : number, CourseName: text, Departmentt: text) ENROLL(RegNo: number, CourseNo: number, Semester: number, TotalMarks: number) TEXTBOOK (Bk_ISBN: number, BookTitle: text, Publisher:text, Author: text) BOOK_ADOPTION (CourseNo: number, Bk_ISBN: number ,Semester: number,) a. Create the above tables by specifying the primary keys and the foreign keys. Create table STUDENT(REGNO int primary key, NAME varchar2(15), MAJOR varchar2(10), BDATE date); Create table COURSE(COURSENO int primary key,COURSENAME varchar2(15), DEPT varchar2(10)); Create table ENROLL(REGNO int,COURSENO int,SEMESTER int,TOTALMARKS int, primary key(REGNO,COURSENO,SEMESTER), foreign key (REGNO) references STUDENT(REGNO), foreign key (COURSENO) references COURSE(COURSENO)); Create table TEXTBOOK(BK_ISBN int primary key,BOOKTITLE varchar2(10), PUBLISHER varchar2(10),AUTHOR varchar2(10)); Create table BOOK_ADOPTION(COURSENO int, BK_ISBN int, SEMESTER int, primary key(COURSENO,BK_ISBN,SEMESTER), foreign key (COURSENO) references COURSE(COURSENO), foreign key (BK_ISBN) references TEXTBOOK(BK_ISBN), foreign key (SEMESTER) references ENROLL(SEMESTER)); b. Enter atleast five tuples for each relation. Insert into STUDENT values(&REGNO,&NAME,&MAJOR,&BDATE); Insert into COURSE values (&COURSENO,&COURSENAME,&DEPT); Insert into ENROLL values (&REGNO,&COURSENO,&SEMESTER,&TOTALMARKS); Insert into TEXTBOOK values (&BK_ISBN,&BOOKTITLE,&PUBLISHER,&AUTHOR);

Insert into BOOK_ADOPTION values (&COURSENO,&BK_ISBN,&SEMESTER); c. Insert a new text book to the database and make this book be adopted by some department. I Insert into TEXTBOOK values(16,physics,ram,sita); Insert into BOOKADOPTION values(17,16,3); Insert into COURSE values(17,zoology,science); d. List the students who have been enrolled select STUDENT.NAME from STUDENT,ENROLL where STUDENT.REGNO = ENROLL.REGNO; e. List the students who have registered but not enrolled select NAME from STUDENT where REGNO NOT IN (select REGNO from ENROLL); f. List the books which have been adopted. Select TEXTBOOK.BOOKTITLE from TEXTBOOK, BOOKADOPTION where TEXTBOOK.BK_ISBN=BOOKADOPTION.BK_ISBN; g. List any department that has all its adopted books published by a specific publisher. Select COURSE.DEPT,COURSE.COURSENAME from COURSE, TEXTBOOK, BOOKADOPTION where COURSE.COURSENO=BOOKADOPTION.COURSENO and BOOKADOPTION.BK_ISBN=TEXTBOOK.BK_ISBN and TEXTBOOK.PUBLISHER=subhas; h. Illustrate inner join ,outer join by joining student and enroll table. (i) (ii) select * from STUDENT INNER JOIN ENROLL on STUDENT.REGNO=ENROLL.REGNO; select * from STUDENT LEFT OUTER JOIN on STUDENT.REGNO=ENROLL.REGNO;

(iii)

select * from STUDENT RIGHT OUTER JOIN on STUDENT.REGNO=ENROLL.REGNO;

--------------------------------------------------------------------------------------------------------------------

Potrebbero piacerti anche