Database Management System Lab (303105204)
PRACTICAL 1
AIM:
1. What is DBMS?
2. What are the applications of DBMS?
3. Create Student Details with Microsoft Excel.
1. What is DBMS?
A Database Management System (DBMS) is a software system that is designed to manage and
organize data in a structured manner. It allows users to create, modify, and query a database, as
well as manage the security and access controls for that database.
2. What are the applications of DBMS?
Data Retrieval: to retrieve data quickly and easily using search queries.
Data Manipulation: provides tools to manipulate data, such as sorting, filtering, and
aggregating data.
Security: provides security features to ensure that only authorized users have access to the
data.
Data Backup and Recovery: provides tools to back up data and recover it in case of system
failures or data loss.
Multiuser Access: allows multiple users to access and modify data simultaneously.
Reporting & Analysis: provides tools to generate reports and analyze data to gain insights and
make informed decisions.
3. Create Student Details with Microsoft Excel.
Database Management System Lab (303105204)
PRACTICAL 2
AIM: Creating tables.
Table: 1 - Employee
Create Table Employee
( Emp_name varchar, Street varchar, City varchar );
Insert Into Employee Values
(‘Adam’, ‘Spring’, ‘Pittsfield’),
(‘Brooks’, ‘Senator, ‘Brooklyn’),
(‘Curry’, ‘North’, ‘Rye’),
(‘Demalo’, ‘SunShine’, ‘San Deago’);
Select * from Employee;
Table: 2 – Work
Create Table Work
( Emp_name varchar, Cmp_name varchar, Salary int );
Insert Into Work Values
(‘Adam’, ‘FBC’, 20000),
(‘Brooks’, ‘MBC’, 30000),
(‘Curry’, ‘SBC’, 10000);
Select * from Work;
Table: 3 – Company
Create Table Company
( Cmp_name varchar, City varchar );
Insert Into Company Values
(‘FBC’, ‘Pittsfield’),
(‘MBC’, ‘Brooklyn’),
(‘SBC’, ‘Rye’);
Select * from Company;
Table: 4 - Manager
Create Table Manager
( Emp_name varchar, Man_name varchar );
Insert Into Manager Values
(‘Adam’, ‘Smith’),
(‘Brooks’, ‘Jones’),
(‘Curry’, ‘Hayes’);
Select * from Manager;
Table: 5 – Sailors
Create Table Sailors
( Sid int, Sname varchar, Rating int, Age int );
Insert Into Sailors Values
(22, ‘Dustin’, 7, 45.0),
(29, ‘Brutus’, 1, 33.0),
(31, ‘Lubber’, 8, 55.5),
(32, ‘Andy’, 8, 25.5),
(58, ‘Rusty’, 10, 35.0),
(64, ‘Horatio’, 7, 35.0),
(71, ‘Zobra’, 10, 16.0),
(74, ‘Horatio’, 9, 35.0),
(85, ‘Art’, 3, 25.5),
(95, ‘Bob’, 3, 63.5);
Select * from Sailors;
Table: 6 - Reserves
Create table Reserves
( Sid int, Bid int, Day date );
Insert into Reserves Values
(22, 101, ‘10-oct-98’),
(22, 102, ‘10-oct-98’),
(22, 103, ‘10-aug-98’),
(22, 104, ‘10-jul-98’),
(31, 102, ‘11-oct-98’),
(31, 103, ‘11-jun-98’),
(31, 104, ‘11-dec-98’),
(64, 101, ‘9-may-98’),
(64, 102, ‘9-aug-98’),
(74, 103, ‘9-aug-98’);
Select * from Reserves;
Table: 7 – Boats
Create table Boats
( Bid int, Bname varchar, Color varchar );
Insert into Boats values
(101, ‘Interlake’, ‘Blue’),
(102, ‘Interlake’, ‘Red’),
(103, ‘Clipper’, ‘Green’),
(104, ‘Marine’, ‘Red’);
Select * from Boats;
Table: 8 – Client
Create table Client
( Cl_no varchar, Name varchar, City varchar, Pincode int, State varchar, Baldue );
Insert into Client values
(‘C0001’, ‘Ivan Bayross’, ‘Mumbai’, 400054, ‘Maharashtra’, 15000),
(‘C0002’, ‘Mamta Muzumdar’, ‘Madras’, 780001, ‘Tamil Nadu’, 100),
(‘C0003’, ‘Chhaya Bankar’, ‘Mumbai’, 400057, ‘Maharashtra’, 5000),
(‘C0004’, ‘Ashwini Joshi’, ‘Bangalore’, 560001, ‘Karnataka’, 500),
(‘C0005’, ‘Hansel Colaco’, ‘Mumbai’, 400060, ‘Maharashtra’, 2000),
(‘C0006’, ‘Deepak Sharma’, ‘Mangalore’, 560050, ‘Karnataka’, 1000);
Select * from Client;
Table: 9 – Product
Create table Product
(
Pr_no varchar, Dscr varchar, Profit int, Unit varchar, Qty int, Reorder_Lvl int, Sell_Price int,
Cost_Price int
);
Insert into Product values
(‘P00001’, ‘T-Shirts’, 5, ‘Piece’, 200, 50, 350, 250),
(‘P00001’, ‘Shirts’, 6, ‘Piece’, 150, 50, 500, 350),
(‘P00001’, ‘Cotton Jeans’, 5, ‘Piece’, 100, 20, 600, 450),
(‘P00001’, ‘Jeans’, 5, ‘Piece’, 100, 20, 750, 500),
(‘P00001’, ‘Trousers’, 2, ‘Piece’, 150, 50, 850, 550),
(‘P00001’, ‘Pull Overs’, 3, ‘Piece’, 80, 30, 700, 450),
(‘P00001’, ‘Denim Shirts’, 4, ‘Piece’, 100, 40, 350, 250),
(‘P00001’, ‘Lycra Tops’, 5, ‘Piece’, 70, 30, 300, 175),
(‘P00001’, ‘Skirts’, 5, ‘Piece’, 75, 30, 450, 300);
Select * from Product;
Table: 10 – Salesman
Create table Product
(
Sl_no varchar, Name varchar, Add1 varchar, Add2 varchar, City varchar, Pin varchar, State
varchar, Amt int, Tgt int, Sales int, Rem varchar
);
Insert into Product values
(‘S00001’, ‘Aman’, ‘A/14’, ‘Worli’, ‘Mumbai’, ‘400002’, ‘Maharashtra’, 3000, 100, 50,
‘Good’),
(‘S00002’, ‘Omkar’, ‘65’, ‘Nariman’, ‘Mumbai’, ‘400001’, ‘Maharashtra’, 3000, 200, 100,
‘Good’),
(‘S00003’, ‘Raj’, ‘P-7’, ‘Bandra’, ‘Mumbai’, ‘400032’, ‘Maharashtra’, 3000, 200, 100,
‘Good’),
(‘S00004’, ‘Ashish’, ‘A/5’, ‘Juhu’, ‘Mumbai’, ‘400044’, ‘Maharashtra’, 3500, 200, 150,
‘Good’);
Select * from salesman;
Table: 11 – Salesorder
Create table Salesorder
(
Od_no varchar, Cl_no varchar, O_dat date, Sl_no varchar, D-Type varchar, Bill varchar, D_dat
date, Status varchar
);
Insert into Salesorder values
(‘O19001’, ‘C00001’, ‘12-JUN-04’, ‘S00001’, ‘F’, ‘N’, ’20-JUL-04’, ‘In Process’),
(‘O19002’, ‘C00002’, ‘25-JUN-04’, ‘S00002’, ‘P’, ‘N’, ’20-JUN-04’, ‘Cancelled’),
(‘O46865’, ‘C00003’, ‘18-FEB-04’, ‘S00003’, ‘F’, ‘Y’, ’20-FEB-04’, ‘Fulfilled’),
(‘O19003’, ‘C00001’, ‘03-APR-04’, ‘S00001’, ‘F’, ‘Y’, ’07-APR-04’, ‘Fulfilled’),
(‘O46866’, ‘C00004’, ‘20-MAY-04’, ‘S00002’, ‘P’, ‘N’, ’22-MAY-04’, ‘Cancelled’),
(‘O19008’, ‘C00005’, ‘24-MAY-04’, ‘S00004’, ‘F’, ‘N’, ’26-JUL-04’, ‘In Process’);
Select * from Salesorder;
Table: 12 – Deposit
Create table Deposit
( Act_no int, Cname varchar, Bname varchar, Amount float, Date date );
Insert into Deposit values
(100, ‘Anil’, ‘VRCE’, 1000.00, ‘1-MAR-95’),
(101, ‘Sunil’, ‘AJNI’, 5000.00, ‘4-JAN-96’),
(102, ‘Mehul’, ‘KAROLBAGH’, 3500.00, ‘17-NOV-95’),
(104, ‘Madhuri’, ‘CHANDI’, 1200.00, ’17-DEC-95’),
(105, ‘Pramod’, ‘M.G.ROAD’, 3000.00, ‘27-MAR-96’),
(106, ‘Sandip’, ‘ANDHERI’, 2000.00, ‘31-MAR-96’),
(107, ‘Shivani’, ‘VIRAR’, 1000.00, ‘5-SEP-95’),
(108, ‘Kranti’, ‘NEHRU PLACE’, 5000.00, ‘2-JUL-95’),
(109, ‘Minu’, ‘POWAI’, 7000.00, ‘10-AUG-95’);
Select * from Deposit;
Table: 13 – Borrow
Create table Borrow
( Loanno int, Cname varchar, Bname varchar, Amount float );
Insert into Borrow values
(201, ‘ANIL’, ‘VRCE’, 1000.00),
(206, ‘MEHUL’, ‘AJNI’, 5000.00),
(311, ‘SUNIL’, ‘DHARAMPETH’, 3000.00),
(321, ‘MADHURI’, ‘ANDHERI’, 2000.00),
(375, ‘PRMOD’, ‘VIRAR’, 8000.00),
(481, ‘KRANTI’, ‘NEHRU PLACE’, 3000.00);
Select * from Borrow;
Table: 14 – Branch
Create table Branch
(
Bname varchar, City varchar
);
Insert into Branch values
(‘VRCE’, ‘NAGPUR’),
(‘AJNI’, ‘NAGPUR’),
(‘KAROLBAGH’, ‘DELHI’),
(‘CHANDI’, ‘DELHI’),
(‘DHARAMPETH’, ‘NAGPUR’),
(‘M.G.ROAD’, ‘BANGLORE’),
(‘ANDHERI’, ‘BOMBAY’),
(‘VIRAR’, ‘BOMBAY’),
(‘NEHRU PLACE’, ‘DELHI’),
(‘POWAI’, ‘BOMBAY’);
Select * from Borrow;
Table:15 - Customers
Create table Customers
( Cname varchar, City varchar );
Insert into Customers values
(‘ANIL’, ‘CALCUTTA’),
(‘SUNIL’, ‘DELHI’),
(‘MEHUL’, ‘BARODA’),
(‘MANDAR’, ‘PATNA’),
(‘MADHURI’, ‘NAGPUR’),
(‘PRAMOD’, ‘NAGPUR’),
(‘SANDIP’, ‘SURAT’),
(‘SHIVANI’, BOMBAY),
(‘KRANTI’, BOMBAY),
(‘NAREN’, BOMBAY);
Select * from Customers;
Database Management System Lab (303105204)
PRACTICAL 3 – Simple Queries
(1) Describe deposit, branch.
Create table Deposit
( Act_no int, Cname varchar, Bname varchar, Amount float, Date date );
Create table Branch
( Bname varchar, City varchar );
(2) Describe borrow, customers.
Create table Borrow
( Loanno int, Cname varchar, Bname varchar, Amount float );
Create table Customers
( Cname varchar, City varchar );
(3) List all data from table DEPOSIT.
Select * from Deposit;
(4) List all data from table BORROW.
Select * from Borrow;
(5) List all data from table CUSTOMERS.
Select * from Customers;
(6) List all data from table BRANCH.
Select * from Branch;
(7) Give account number and amount of depositors.
Select Act_no, Amount from Deposit;
(8) List all data from SAILORS.
Select * from Sailors;
(9) List Boat Name and its color.
Select Bname, Color from Boats;
(10) List Employee name and its city.
Select Emp_name, City from Employee;
(11) List all the details of Client.
Select * from Client;
(12) Describe various products and its price.
Select Dscr, Sell_Price, Cost_Price from Product;
(13) Describe sailor’s name, age and its rating.
Select Sname, Age, Rating from Sailors;
(14) Describe the managers of various employees.
Select Emp_name, Man_name from Manager;
(15) Describe the details of Loan for customers.
Select * from Borrow;
(16) Describe the date of travel of various sailors.
Select Sailors.Sid, Sailors.Sname from Sailors INNER JOIN Reserves ON
Sailors.Sid=Reserves.Sid;
Database Management System Lab (303105204)
PRACTICAL 4 – Simple Queries
(1) Give name of depositors having amount greater than 4000.
Select Cname from Deposit where Amount>4000;
(2) List the employees having salary less than 22000.
Select Emp_name, Salary from Work where Salary<22000;
(3) List the sailors having age more than 25.
Select Sid, Sname from Sailors where Age>25;
(4) List the boats travelling on 10-oct-98
Select Bid from Reserves where Day= ’10-oct-98’;
(5) List the details of boat “Interlake”.
Select * from Boats where Bname = ‘Interlake’;
(6) List the details of the red colored boat.
Select * from Boats where Color = ‘Red’;
(7) List the details of clients whose city is Mumbai.
Select * from Client where City = ‘Mumbai’;
(8) List Client Name, due balance and city of the clients having balance greater than 1500.
Select Name, Baldue, City from Client where Baldue>1500;
(9) Describe the details of products having selling price less than 500.
Select Pr_no, Dscr from Product where Sell_Price<500;
(10) List the products for which quantity ordered is less than 120 and cost price is greater
than 250.
Select Pr_no, Dscr from Product where Reorder_Lvl<120 AND Cost_Price>250;
(11) Display account details having amount greater 2200.
Select Act_no, Amount from Deposit where Amount>2200;
(12) Display all the customers staying in Nagpur.
Select cname from Customers where City= ‘Nagpur’;
(13) Display the names of sailors having rating greater than 7.
Select Sname from Sailors where Rating>7;
Database Management System Lab (303105204)
PRACTICAL 5 – LIKE Queries
(1) Display all customers whose name start with ‘M’.
Select Cname from Customers where Cname Like ‘M%’;
(2) Display all the customers whose name ends with ‘L’.
Select Cname from Customers where Cname Like ‘%L’;
(3) Display all loan details whose branch starts with ‘A’.
Select * from Borrow where Bname Like ‘A%’;
(4) Display the details of sailors whose name is minimum 6 characters long.
Select * from Sailors where length(Sname)>=6;
(5) Display the details of Employees whose address starts with ‘S’.
Select * from Employee where Street Like ‘S%’;
(6) List the details of the boat ending with ‘e’.
Select * from Boats where Bname Like ‘%e’;
(7) List the details of clients having ‘h’ as a 3rd character in his/her name.
Select * from Client where Name Like ‘__h%’;
(8) List Client Name, due balance and city whose pin code starts with 4.
Select Name, Baldue, City from Client where Pincode between 400000 and 499999;
(9) List all customers whose city contains ‘a’ as second character.
Select Cname from Customers where City Like ‘_a%’;
(10) List client names and city whose state has ‘a’ as fourth or fifth character.
Database Management System Lab (303105204)
PRACTICAL 6 – Aggregate functions and DML Queries
(1) List total deposit from deposit.
Select SUM(Amount) AS ‘Total_Deposit’ from Deposit;
(2) Give maximum loan given to the customer.
Select MAX(Amount) AS Maximum_Loan_Given_to_Customer from Borrow;
(3) Describe the average age of all the sailors.
Select AVG(Age) AS Average_Age from Sailors;
(4) Count total number of customers.
Select COUNT(Cname) AS total_number_of_customers from Customers;
(5) Count total number of customer’s cities.
Select COUNT(City) AS total_number_of_city from Customers;
(6) Display total target for the salesman.
Select SUM(Tgt) from Salesman;
(7) Update the salary of the employee having 10000 to 11500.
Update Work Set Salary=11500 where Salary=10000;
(8) Update the city of client from Bangalore to Bengaluru.
Update Client Set City= ‘Bengaluru’ where City= ‘Bangalore’;
(9) Give the 15% hike in the salary of all the Employees. Rename that column to “New
Salary”.
Select Emp_name, Cmp_name, Salary*15/100 AS New_Salary from Work;
(10) Increase the sell price of all products by 20% and label new column as “New Sell
Price”.
Select Sell_Price*20/100 AS ‘New Sell Price’ from Product;
(11) Provide the count of customers staying in “Bombay”.
Select COUNT(Cname), Customers.City from Customers where City= 'BOMBAY' Group by
City;
Database Management System Lab (303105204)
PRACTICAL 7 – Join Queries
(1) Find the salary of Adam.
Select Emp_name, Salary from Work where Emp_name= ‘Adam’;
(2) Find the city where Brooks work.
Select Work.Emp_name, Company.City from Work INNER JOIN Company ON
Work.Cmp_name = Company.Cmp_name where Emp_name='Brooks';
(3) Display the sailor’s details whose boat is booked for 9th May, 98.
Select * from Sailors INNER JOIN Reserves ON Sailors.Sid = Reserves.Sid WHERE Day =
‘9-may-98’;
(4) Display the day of ride and sailor name for boat 103.
Select Sailors.Sname, Reserves.Day from Sailors INNER JOIN Reserves ON Sailors.Sid =
Reserves.Sid WHERE Bid = 103;
(5) Display the sailor name and its age for Red colored and 101 boat.
Select Sailors.Sname, Sailors.Age from Sailors INNER JOIN Reserves ON Sailors.Sid =
Reserves.Sid INNER JOIN Boats ON Reserves.Bid = Boats.Bid WHERE Reserves.Bid = 101
AND Color = ‘Red’;
(6) Display the sailor details whose boat is never booked.
Select Sid, Sname, Rating, Age, Bid from Sailors INNER JOIN Reserves ON Sailors.Sid =
Reserves.Sid WHERE Day = ‘NULL’;
Answer: Output will be empty set.
(7) Display the sailor name that has Red or Green Boat.
Select Sailors.Sname, Boats.Color from Sailors INNER JOIN Reserves ON Sailors.Sid =
Reserves.Sid INNER JOIN Boats ON Reserves.Bid = Boats.Bid WHERE Color = ‘Red’ OR
Color = ‘Green’;
(8) Display all sailor details and boat details and who has Interlake boat.
Select * from Sailors INNER JOIN Reserves ON Sailors.Sid = Reserves.Sid INNER JOIN
Boats ON Reserves.Bid = Boats.Bid WHERE Bname = ‘Interlake’;
(9) Display sailor’s rating with boat details or the trip on 10th October, 98.
Select * from Sailors INNER JOIN Reserves ON Sailors.Sid = Reserves.Sid INNER JOIN
Boats ON Reserves.Bid = Boats.Bid WHERE Day = ‘10-oct-98’;
(10) Display the sailor id and name whose age is more than 42 or who has Blue colored
boat.
Select Sid, Sname, Age, Color from Sailors INNER JOIN Reserves ON Sailors.Sid =
Reserves.Sid INNER JOIN Boats ON Reserves.Bid = Boats.Bid WHERE Age > 42 AND Color
= ‘Blue’;
(11) Display name and rating of sailor whose boat name is Clipper.
Select Sname, Rating, Bname from Sailors INNER JOIN Reserves ON Sailors.Sid =
Reserves.Sid INNER JOIN Boats ON Reserves.Bid = Boats.Bid WHERE Bname = ‘Clipper’;
(12) List products whose selling price is more than 500 and less than equal to 750.
Select Product.Pr_no, Product.Dscr from Product WHERE Sell_Price BETWEEN 500 AND
750;
(13) Describe the second highest salary of an employee.
Select * from Work ORDER BY Salary DESC;
(14) Display the date of travel and sailor’s name whose age is between 35 and 65.
Select Sailors.Sname, Sailors.Age, Day from Sailors INNER JOIN Reserves ON Sailors.Sid =
Reserves.Sid INNER JOIN Boats ON Reserves.Bid = Boats.Bid WHERE Age BETWEEN 35
AND 65;
(15) List all the employees working for “FBC”.
Select Emp_name from Work WHERE Cmp_name = ‘FBC’;
Database Management System Lab (303105204)
PRACTICAL 8 – Join Queries
(1) Display all the employee name and the city where they work.
Select Work.Emp_name, Company.City from Work INNER JOIN Company ON
Work.Cmp_name = Company.Cmp_name;
(2) Display the employee name and company’s name having salary more than 15000.
Select Emp_name, Cmp_name from Work WHERE Salary > 15000;
(3) Find the average rating and age of all sailors.
Select AVG (Rating), AVG (Age) from Sailors;
(4) List various products available.
Select Pr_no, Dscr from Product;
(5) Display the names of salesman who have salary more than 2850.
Select Sl_no, Name WHERE Amt > 2850;
(6) Change the cost price of Trousers to 950.
Update Product SET Cost_Price = 950 WHERE Dscr = ‘Trousers’;
(7) List all the clients having “a” as a second character in their names.
Select Name from Client WHERE Name LIKE ‘_a%’;
(8) Print the description and total qty sold for each product.
Select Pr_no, Dscr, Qty from Product;
(9) Find out all the products which have been sold to “Ivan Bayross”.
Select Pr_no, Dscr from Product INNER JOIN Salesorder_Details ON Product.Pr_no =
Salesorder_Details.Pr_no INNER JOIN Salesorder ON Salesorder_Details.Od_no =
Salesorder.Od_no INNER JOIN Client ON Slaesorder.Cl_no = Client.Cl_no WHERE Name =
‘Ivan Bayross’;
Answer: Empty Set.
(10) List the client details who place order no. O19001.
Select Client.Cl_no, Client.Name, Client.City, Client.Pincode, Client.State, Client.Baldue
from Client LEFT JOIN Salesorder ON Client.Cl_no = Salesorder.Cl_no where Od_no=
‘O19001’;
Answer: Empty Set.
Database Management System Lab (303105204)
PRACTICAL 9 – Miscellaneous Queries
1. Find the average rate for each Order.
2. Give the loan details of all the customers.
3. List the customer’s name having loan account in the same branch city they live in.
4. Provide the loan details of all the customers who have opened their accounts after
August 1995.
5. List the order information for client C00001 and C00002.
6. List all the information for the order placed in the month of June.
7. List the details of clients who do not stay in Maharashtra.
8. Determine the maximum and minimum product price. Rename the output as
Max_Price and Min_Price.
9. Count the number of products having price less than or equal to 500.
10. List the order number and the day on which client placed an order.
11. List the clients who placed order before June.
12. List all the clients who stays in Bengaluru or Mangalore
Database Management System Lab (303105204)
PRACTICAL 10 – PL/SQL Queries
1. Write a PL/SQL Block to Add 2 Numbers.
2. Write a PL/SQL Block to find Area of Rectangle, Triangle and Square.
3. Write a PL/SQL Block to find Maximum of 3 numbers.
4. Write a PL/SQL Block to print sum of N Numbers using For Loop.
5. Write a PL/SQL Block to generate Fibonacci series of N numbers.