DBMS Lab Manual
DBMS Lab Manual
DBMS Lab Manual
Question #2: Library database has a table with the following attributes
LIBRARY (BOOKID: Number, Title: Text, Author: Text, Publication: Text, Year_pub:
number, Price:number (6,2)).
Consider the insurance database given below. The primary keys are underlined and
the data types are specified.
1. Create the above tables by specifying primary key and foreign keys.
2. Enter at least 5 tuples in each relation.
i. Update the damage amount of the car with a specific regno in accident with
report number 12 to 25000.
ii. Add a new accident to the database
3. Find the total number of people who owned cars that were involved in accident in 2002
4. Find the number of accident in which car belonging to a specific model were involved.
Consider the following database of student enrollment in courses and books adopted
for each course
1) create the above tables by properly specifying the primary keys and foreign keys
2) Enter 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_no, Book_ISBN, Book_Title) in the
Alphabetical order for Course offered by ‘BCA’ Department that use more than two books
5) List any department that has all its adopted books published by a specific publisher
Question #6: BANK DATABASE Consider the following database for BANK
BRANCH(Bname: text, Bcity text, Asset number)
ACCOUNT( Accno: int, Bname String, balance real)
CUSTOMER(CName: string, Cstreet: string, Ccity string)
DEPOSITOR(Cname: string, Accno int)
LOAN(loan_no int: Bname: string, amount real)
BORROWER(Cname string, Loan_no int)
1. Create above tables by properly specifying the primary keys and the foreign keys
2. Enter atleast five tuples for each realtions
3. Find all the customer who have atleat two accounts at the main Branch (Ex: KG
Road)
4. Find all Customer who have an account at all the Branches located in a specific
city (Bangalore)
5. Demonstrate how you delete all Account tuples at every branch located in a
specific city (Ex: Bangalore)
1. create above tables by properly specifying primary keys and foreign keys.
2. Enter atleast five tuples for each realtions
3. List the Order number and Shipdate for all orders shipped from a particular
warehouse.
Department of BCA -AIMS Page 2
DBMS Lab Manual
4. Produce a listing Customer Name, No.of Orders,Avg Oreder AMount where the
middle column is the total average Order Amount for that customer.
5. List the orders that were not shipted within 30 days of ordering.
Part B
1. Consider the following table with the mapping given below.
RETAILOR(Cust_id: int, Cust_name: string , place: string, ph_no integer, pan_no: string).
a) Create the above table by specifying primary key.
b) Alter the table to add a column pin_no.
c) Enter 5 tuples into the table.
d) Display the details of customer who are all living in Bangalore.
e) Display the customer name whose first letter is ‘S’.
a) Create the above tables by properly specifying the primary keys and foreign keys.
b) Enter at least five tuples for each relation.
c) List the employees of employee table in descending order of their salaries.
d) List the details of highest paid employee in ‘SALES’ department.
e) List the employee number, employee name and department name for all employee of
departments in 50 and 60.
4. An inventory database has the following tables. The primary keys are underlined.
ITEM(itemno: number, ItemName:Text, Price: Number(10,2))
PURCHASE(itemno: number, Quantity: number)
a) Create the above tables by specifying primary key and foreign keys.
b) Enter 5 tuples into the tables
c) List the item purchased.
d) Display the total items purchased (listing must have the columns; itemcode,
itemname, totalQuantity)
e) List the items which are not purchased by any one.
5. A bank customer database has two tables CUSTOMER and ACCOUNT
ACCOUNT(Accno: number, Acctype: text, Branch: text, AccStatus: text,
ChequeFacility: Text)
CUSTOMER (Custno: number, Custname: Text, City :text, AccNo: Number, Balance:
Number(10,2))
a) Create the above tables by specifying primary key and foreign keys.
b) Enter 5-8 tuples into the tables
c) List the customer from “Bangalore” who have cheque facility.
d) List all the customer whose balance is grater than 3000 and have an active account.
e) Find the current outstanding balance amount of branch “Peenya”.
Display Schema
sp_help student
sp_help student
Column Name Data Type Size constraint
Regno numeric 10 Primary Key
Name varchar 15 not null
DateofBirth datetime 8 not null
sp_help student
Column Name Data Type Size constraint
Regno varchar 10
Name varchar 15 not null
DateofBirth datetime 8 not null
sp_help student
Column Name Data Type Size constraint
Regno varchar 10
Name varchar 15 not null
DateofBirth datetime 8 not null
PhoneNo Numeric 10
sp_help library
Publisher
AIMS
Pearson
PHI
Sky word
Sumuka
sp_help empsalary;
sum of salary
346100.00
max salary
250000.00
min salary
100.00
Department of BCA -AIMS Page 10
DBMS Lab Manual
sp_help person;
sp_help CAR;
sp_help Owns;
Column name type size
DriverId varchar 10
Regno varchar 10
sp_help Accident;
sp_help Participated;
DriverId RegNo
D101 KA54A8181
D104 KA09Z7272
D102 KA01N5454
D103 KA36M1818
D105 KA06M6363
3.1 Update the damage amount of the car with a specific regno
in accident with report number 12 to 25000.
Before Updating:
After Updating
select * from participated where reportno = 12;
DriverId Regno ReportNo Dmg_amt
D104 KA09Z7272 12 25000.00
4 Find the total number of people who owned cars that were
involved in accident in 2009
No of Accident in 2009
2
'No of Accident'
2
sp_help Student;
sp_help Course
sp_help Enroll
sp_help Text
sp_help Book_adoption
3) Demonstrate how you add a new text book to the database and
make this book be adopted by some department
5) List any department that has all its adopted books published
by a specific publisher
DEPT CNAME
IT BCA
IT BCA
MGT BBM
Author(Author_id:int,name:string,city:string,country String)
Publisher(Publisher_id:int,Pname:String,city: String,
country:String)
Category(Category_id:int,Description varchar(30),
Catalog(Book_id:int,Title:String,Authour_id:int,Publisher_id:i
nt,Category_id:int,year:int,price real)
Order_details(Order_id:int,Book_id:int,Quantity:int)
Category_id Descriptiobbn
1001 Database Mangement System
1002 Software Engineering
1003 Data Communication Network
1004 Data Structure Using C
1005 Operating System
Authour_ID Name
101 Malini
103 Swamy
Cname Accno
Manveer 105
Rohit 104
Sadam 103
Shubham 101
Shuvonabo 102
Cname LoanNO
Manveer 504
Shuvonabo 502
Shubham 501
Sadam 503
Rohit 505
Cname Accno
Shuvonabo 106
Shuvonabo 106
Shuvonabo 106
warehouseno City
1001 Bangalore
1002 Hubli
1003 Mysore
1004 Tumkur
1005 Kolar
3. List the Order number and Shipdate for all orders shipped
from a particular warehouse.
Part B
1. Consider the following table with the mapping given
below.
RETAILOR(Cust_id: int, Cust_name: string , place:
string, ph_no integer, pan_no: string).
a) Create the above table by specifying primary key.
b) Alter the table to add a column pin_no.
c) Enter 5 tuples into the table.
d) Display the details of customer who are all living in
Bangalore.
e) Display the customer name whose first letter is ‘S’.
sp_help Retailor
232323234,'334RF324',560058);
insert into retailor values(555,'Manjunath','Hubali',
773344556,'224DE435',56005);
sp_help Department
sp_help Employee
ename varchar 10
designation varchar 20
manager varchar 20
hiredate datetime 8
salary numeric 5
deptno int 4
sp_help STU_DETAILS
sp_help MARK_DETAILS
column name type size
reg_no int 4
marks1 int 4
marks2 int 4
marks3 int 4
total int 4
c)Display only those rows whose total ranges between 250 and
300.
select s.reg_no, m.total from stu_details s, mark_details m
where s.reg_no = m.reg_no and total between 250 and 300;
reg_no total
11 255
44 280
(1 row(s) affected)
f)List all the student detail that who are all located in
Tumkur.
itemno qty
101 25
102 17
103 30
105 12
105 13
itemno itemname
104 Scale
106 Pen Drive
Sp_Help Account;
Sp_Help Customer;
City Varchar 25
Accno Numeric 20
Balance Numeric 10,2
4.List All The Customer Whose Balance Is Grater Than 3000 And
Have An Active Account.
Custname Balance
Nandini 30001.00
Deepak 22222.00
Jagadeesh 50000.00
SELECT @MARKS1=59
SELECT @MARKS2=55
SELECT @MARKS3=51
SELECT @AVG = (@MARKS1+ @MARKS2 + @MARKS3)/3
IF (@MARKS1 <50 OR @MARKS2<50 OR @MARKS3<50)
BEGIN
PRINT 'MARKS :' + CONVERT(CHAR(5),@AVG)
PRINT 'RESULT : FAILED'
END
ELSE
IF @AVG>=70
BEGIN
PRINT 'MARKS :' + CONVERT(CHAR(5),@AVG)
PRINT 'RESULT : PASSED WITH DISTINCTION'
END
ELSE IF @AVG>=60
BEGIN
PRINT 'MARKS :' + CONVERT(CHAR(5),@AVG)
PRINT 'RESULT : PASSED WITH FIRST CLASS'
END
ELSE
BEGIN
PRINT 'MARKS :' + CONVERT(CHAR(5),@AVG)
PRINT 'RESULT : PASSED WITH SECOND CLASS'
END
DECLARE @I INT
DECLARE @FACT INT
BEGIN
SELECT @I = 5
SELECT @FACT =1
WHILE @I>=1
BEGIN
SELECT @FACT =@FACT*@I;
SELECT @I=@I-1
END
PRINT 'FACTORIAL :' + CONVERT(CHAR(5),@FACT)
END;
DECLARE @I INT
DECLARE @N INT
DECLARE @F1 INT
DECLARE @F2 INT
DECLARE @F3 INT
BEGIN
SELECT @I = 3
SELECT @N = 8
SELECT @F1 =0
SELECT @F2 =1
PRINT 'FIBONACCI SERIES IS :'
PRINT CONVERT(CHAR(5),@F1)
PRINT CONVERT(CHAR(5),@F2)
WHILE @I <=@N
BEGIN
SELECT @F3 = @F2 + @F1
PRINT + CONVERT(CHAR(5),@F3)
SELECT @F1 = @F2
SELECT @F2 = @F3
SELECT @I=@I+1
END
END;
BEGIN