DBMS - 24-25 - Lab Manual
DBMS - 24-25 - Lab Manual
GHAZIABAD
LAB MANUAL
(HoD IT)
AKGEC/LP/BCS-551/01
LIST OF EXPERIMENTS
6 Execute queries related to Exists, Not Exists, Union, Intersection, Difference, Join
on tables CLIENT_MASTER, PRODUCT_MASTER, SALESMAN_MASTER,
SALES_ORDER, SALES_ORDER_DETAILS
*Innovative Exeriments
# Virtual Lab Experiments
(HoD CSE)
AJAY KUMAR GARG ENGINEERING COLLEGE, GHAZIABAD
Department of Computer Science & Engineering
PEO 1. The graduate of CSE will have a strong foundation in mathematical, scientific, and
engineering fundamentals necessary to formulate, solve and analyze engineering problem in
their career.
PEO 2. The graduate of CSE will have the ability to analyses the requirements, understand
the technical specification, and design the much engineering solutions by applying computer
science theory and principles.
PEO 3. The graduates of CSE will have exposure to work as teams on emerging cutting-edge
technologies with effective communication skills and leadership qualities.
PEO 4. The graduates of CSE will have successful career by engaging in lifelong learning.
PEO 5. The graduates of CSE will have skills to work collaboratively on multidisciplinary
projects and exhibits high levels of professional and ethics values.
C312.2
3 3 3 3 2 2 3 2
BCS 551
Database
Management
C312.3
System
3 3 2 3 2 3 3 2
Lab
C312.4
2 2 3 2 3 3 3 2
C312.5
3 3 3 3 2 1 3 3
Implementation:
Ans:
a) select name from client_master ;
Output:
NAME
--------
Akshita
Dhawal
Akansha
Divya
4 rows selected
4 rows selected
2 rows selected
1 row selected
3 row selected
2 rows selected
Ans :
a) Update client-master set city=’Noida’ where city=’Dhampur’;
Q-f) Create table New_client from client_master with the fields Client_no, name
Ans :
create table new-client(client_no,name) as (select client_no,name from
client_master);
Output:Table created
Q-g) Insert into table new_client data from table client_master where city = ‘Hapur’
Ans: insert into new_client select client_no.,name from client-master where city=’Hapur’;
Output:
Client_no. Name
6 Divya
1 row created
a) Add a column called Telephone_no of data type number and size = 10 to the
client_master table
b) Change the size of the description column in product_master to 25
c) Drop the column Telephone_no from the table client_master
Ans:
a) alter table client_master add(telephone_number(10));
Output:Table created
b) alter table product_master modify(description varchar(25));
Output:Table created
c) alter table client_master drop column telephone_no;
Output:Table created
Program Name:
Application of operators, date conversion functions:
a. Application of operator on a column
b. Application of operator and renaming of column
c. Use of AND operator
d. Use of OR
e. Use of BETWEEN
f. Use of NOT BETWEEN
g. USE of LIKE
h. USE of LIKE with OR
i. Use of IN
j. Use of NOT IN
k. Use of Conversion functions like TO_CHAR, TO_DATE etc.
Theory Concepts:
This experiment deals with commands of SQL which are used to print data from a table with
various conditions. It also deals with various in built commands like max(), min(), sqrt(),
round(), trim(), etc. The program would print the current system date and time using the
different commands.
Implementation:
Computation on Tables:
d)Select client_no, name, city from client_master where pincode = 201001 ORpincode =
201009;
Output:
CLIENT_NO NAME CITY
3 Akshita Ghaziabad
h)Select * from client_master where name like ‘_r%’ OR name like ‘_h%’;
Output:
CLIENT_NO NAME CITY PINCODE STATE
4 Dhawal Ghaziabad 24364 UP
i)Select from client_masterclient_no, name, city where name IN(‘Ajay’, ‘Vijay’, ‘Amit’);
Output:
No rows selected
j)Select from client_masterclient_no, name, city where name NOT IN(‘Ajay’, ‘Vijay’,
‘Amit’);
Output:
CLIENT_NO NAME CITY
3 Aksita Ghaziabad
4 Dhawal Ghaziabad
5 AkanshaDharampur
k)CONVERSION FUNCTIONS:
Theory Concept:
This program intends to explore various constraints enforced on the database like NOT
NULL, UNIQUE constraint etc. Primary kay is an attribute of table which is used to identify
each row of the table uniquely. Foreign key is used to reference other tables.
Implementation:
Q-1) Create table Employee with attributes eno, name, salary and the constraints that
eno and name cannot be NULL
Ans: create table employee(eno number NOT NULL, name varchar(20) NOT NULL,salary
number);
Output:
Table created
Q-2) Insert data into the table Employee.Then Test the NOT NULL constraint with
appropriate data.
Ans:insert into employee (eno,name,salary) values(2,'Amit',20000);
Output:1 row inserted
Q-5) Insert records into the above table. Test the UNIQUE constraint with
appropriate data
Ans: insert into department (dno,dname,no_of_employees) values(1,'EC',20);
Output: 1 row inserted
Q6) Create table Project with attributes pno, pname, location and pno as the
primary key
Ans: create table Project (pnonumber,pnamevarchar(20),location varchar(20),PRIMARY
KEY(pno));
OR
Q8) Create table works_on with attributes eno, pno and hours where eno is foreign
key referencing eno from Employee table and pno is the foreign key referencing pno
from Project Table. Let {eno,pno} be the primary key for table Works_on
Ans: create table works_on(eno number REFERENCES Employee, pno number
REFERENCES Project, Hours number ,PRIMARY KEY(eno,pno));
Output: Table created
Q-10) Select appropriate records from the table Works_on by referencing the table
Employee and Project
Ans:select employee.eno,employee.name,project.pno,project.pname,works_on.hours from
works_on,employee,project
where (works_on.eno = employee.eno and works_on.pno = project.pno);
Output:
ENO NAME PNO PNAME HOURS
---- -------------------- ---------- -------------------- ----------
2 Amit 1 asd 8
2 Amit 2 sjxks 9
1 SAmit 1 asd 23
1 SAmit 2 sjxks 30
4 rows selected
Q-11) Create table person with attributes ssno, name city such that all ssno have ‘C’ as
the first character, all names are entered in uppercase and city is either Delhi or
Mumbai or Bangalore
Ans:Create table person(ssnovarchar(3) CHECK(ssno LIKE 'C%'),name varchar(20)
CHECK (name = upper(name)), city varchar(20) CHECK (city
IN('Delhi','Mumbai','Bangalore')));
Program Name:
Execute queries related to Group By and Having Clause on tablesSALES_ORDER.
Theory Concept:
The program aims to familiarize the user with grouping of data based on conditions to ensure
better usability of data.
Implementation:
GROUP BY
Q1) Create table sales_order with attributes product_no and Qty. Insert records
into the table and find the total qty ordered for each product_no.
Ans: Create table sales_order (product_novarchar(10), Qty numbe(4));
Output: Table created.
insert into sales_order values(&product_no, &qty);
6 rows selected.
HAVING clause
Q2) Find the total Qty for product_no ‘p1’ and ‘p2’ from the table sales_order
Ans:select product_no, sum(qty) from sales_order group by product_no
havingproduct_no = 'p1' OR product_no = 'p2';
Output:
PRODUCT_NO SUM(QTY)
---------- ----------
p1 21
p3 46
2 rows selected
Experiment- 5
Program Name:
Execute Nested Queries on tables CLIENT_MASTER, PRODUCT_MASTER,
SALESMAN_MASTER, SALES_ORDER, SALES_ORDER_DETAILS
Theory Concept:
The program intends to familiarize nested queries so as to retrieve data from a record by
using filtered data from another record.
Implementation:
Q1) Retrieve the order numbers, client names and their order dates from client_master and
sales_order tables.
Q2) Retrieve the product numbers, description and total quantity ordered for each product
Ans:Selectsales_order_details.product_no, description, sum(qty_ordered) from
sales_order_details, product_master where product_master.product_no =
sales_order_details.product_no group by sales_order_details.product_no, description;
OUTPUT :
product_no description sum(qty_ordered)
-----------------------------------------------------------
1 chair 2
2 pen 5
Q3) Retrieve the names of employees and names of their respective managers from the
employee table.
Ans: Select employee.name, employee.name from employee where employee.manager_no =
employee.employee_no;
OUTPUT :
Name Name
------------------------------
Akansha Divya
Akshita Divya
UNION , INTERSECT and MINUS CLAUSE
Q1) Retrieve the names of all clients and salesmen in the city of Mumbai from the
tablesclient_master and salesman_master.
Ans:Selectsalesman_no from salesman_master where city = ‘Mumbai’
UNION
Select client_no from client_master where city = ‘Mumbai’;
OUTPUT :
Name
------------------------------
Akansha
Akshita
Divya
Q2) Retrieve the salesman name in Mumbai whose efforts have resulted into atleast one
sales transaction
Ans:Selectsalesman_no, name from salesman_master where city = ‘Mumbai’
INTERSECT
Select salesman_master.salesman_no, name from salesman_master, sales_order where
salesman_master.salesman_no = sales_order.salesman_no;
OUTPUT :
Saleman_noName
------------------------------
1 akansha
2 divya
Q3) Retrieve all the product numbers of non-moving items from the product_master table
Ans:Selectproduct_no from product_master
Minus
Select product_no from sales_order_details;
OUTPUT :
product_no
---------------
3
4
VIEWS
Theory Concept:
The program retrieves data from records by defining relation between two tables so as to
retrieve filtered records.
Implementation:
Correlated queries with EXISTS/NOT EXISTS clause
2)Selectorder_no and order_date for all orders which include product_no ‘P001’ and
quantity_ordered>10
Ans:Select order_no,order_data from sales_order where exists(select * from
sales_order_details where sales_order_details,order_no = sales_order.Order_no and
product-no=’p001’ and quantity-ordered>10;
Output :
Order_no Product_no
0002 05/feb/13
Order_no
0003
Order_no Order_date
0001 23/jan/13
Client_no Name
3 Akshita
4 Dhawal
2)List all the clients and their names who are also salesman.
Ans:Select name from client_masterINTERSECT,select name from salesman_master;
Output :
No rows selected
Name
Akshita
Dhawal
Akansha
Divya
Dorothy
Client_no
6
7
5)List all the clients who have not placed any order.
Client_no
3
4
5
Client_no
3
4
5
7)Find all the clients and their names from city Ghaziabad who have delivery date of their
orders as today.
Ans:Select client_no from client_master where city=’Ghaziazbad’ INTERSECT select
client_no from sales_order where delivery_date=’09-MAR-13’
Output :
Client_no
5
Queries on Joins
3)Find the products and their quantities that will have to be delivered in the current month.
7)Find the products and their quantities for the orders placed by the client_no ‘3’ and ‘5’
Ans:Select product_no, description, qty_orderedfrom(product1 natural join
sales_order_details natural join sales_order natural join client_master) where (client_no=3
OR client_no=5);
Output :
PRODUCT_NO DESCRIPTION QTY_ORDERED
1 Chair 4
1 Chair 3
3 Sofa 2
Experiment- 7
Program Name: Procedures, Functions & Packages:
a. Write a simple procedure to display a message “Good Day to You”
b. Code a function to return the Square of a given number.
c. Create a package to include the following:
A named procedure to list the Product_no of products with Quantity_on_hand
as 5 in PRODUCT_MASTER table.
A function which returns the max maximum Quantity_on_hand for a given
product.
Theory Concept:
The program would print the message using a procedure in .
Implementation:
Ans(a):
Ans(b):
CREATE OR REPLACE FUNCTION square(original NUMBER)
RETURN NUMBER
AS
original_squared NUMBER;
BEGIN
original_squared := original * original;
RETURN original_squared;
END;
Ans(c):
Experiment- 9
Theory Concept: The following example would illustrate the concept of CURSORS. We
will be using the CLIENT_MASTER table and display records.
Implementation:
DECLARE
CURSOR client_cur is
SELECT id, name, address
FROM client_master;
client_rec client_cur%rowtype;
BEGIN
OPEN client_cur;
LOOP
FETCH client_cur into client_rec;
EXIT WHEN client_cur%notfound;
DBMS_OUTPUT.put_line(client_rec.id || ' ' || client_rec.name);
END LOOP;
END;
/
Output: When the above code is executed at SQL prompt, it produces the following result:
1 Ramesh
2 Khilan
3 kaushik
4 Chaitali
5 Hardik
6 Komal
Theory Concept: To install the software, you must use the Universal installer.
Implementation:
1. For this installation, you need either the DVDs or a downloaded version of the DVDs. In this
tutorial, you install from the downloaded version. From the directory where the DVD files were
unzipped, open Windows Explorer and double-click on setup.exe from the \db\Disk1 directory.
2. The product you want to install is Database 11g. Make sure the product is selected and
click Next.
3. You will perform a basic installation with a starter database. Enter orcl for the Global Database
Name and for Database Password and Confirm Password. Then, click Next.
4. Configuration Manager allows you to associate your configuration information with your
Metalink account. You can choose to enable it on this window. Then, click Next.
5. Review the Summary window to verify what is to be installed. Then, click Install.
6. The progress window appears.
Theory Concept: Entity relationship diagram (ERD) is a kind of diagram for presenting
visually the structure of relational database. In this experiment we will make use of ERD to
model the database structure of a simple bus route management system.
Implementation:
1. Start Visual Paradigm. Select a new workspace folder for this tutorial.
2. Select Project > New from the toolbar to create a project. Name the project as Bus Route
Management and confirm.
3. To create an ERD, select Diagram > New from the toolbar. In the New Diagram window,
select Entity Relationship Diagram and clickNext. Enter Bus Route Management as
diagram name and click OK.
4. Let's start by creating the first entity Route. Select Entity in diagram toolbar and click on the
diagram to create an entity. Name the entityRoute and press Enter to confirm.
5. Create columns in Route. Let's start with a primary key. Right click on entity Route and
select New Column from popup menu.
6. Enter +id : varchar(10) and press Enter. Note that the + sign means that the column is a
primary key. Varchar is the column type and 10 is the length.
7. Enter fare : float and press Enter, then Esc to create another column.
8. Create entity Stop. A bus route has many bus stops, while a stop can be shared by many
routes. Therefore, there is a many-to-many relationship between Route and Stop. Place the
mouse pointer over the Route entity. Drag out the Resource Catalog icon at top right.
9. Release the mouse button and select Many-to-Many Relationship -> Entity from Resource
Catalog.
Name the new entity Stop, You can see that a linked entity Route_Stop is automatically
created in between Route and Stop, with foreign key added.
PK id int(10)
name varchar(255)
terminus blob
11.
The diagram should now become:
12. A route has multiple bus schedules. Create an entity Schedule from Route with a
one-to-many relationship. Move the mouse pointer toRoute. Press and drag out the Resource
Catalog icon. Select One-to-Many Relationship -> Entity to create entity Schedule.
PK id int(10)
departure date
arrive date
14. A schedule is handled by a bus. Create an entity Bus from Schedule, with an one-to-one
relationship. Create the following columns inBus:
Key Name Type
PK vehicle_id int(10)
fleet_id varchar(10)
last_main date
15. The diagram should become:
16. A bus is driven by a bus driver. Create entity Driver from Bus with a one-to-one relationship.
Add the following columns to Driver:
Key Name Type
PK id int(10)
name varchar(255)
employ_date date
Program Name:
PL/SQL programming
a. Write a PL/SQL block code to print the squares of numbers upto 99.
b. Write a PL/SQL block code to insert data into table CUSTOMER
Theory Concept:
The program would print the squares of numbers upto 99 using for loop and data into table
CUSTOMER in pl/sql.
Implementation:
Ans (a):
DECLARE
BEGIN
for x in 1..99
loop
dbms_output.put_line(x * x);
end loop;
end;
Output:
Implementation:
Ans:(b)
desc customer;
Name Null? Type
----------------------------------------- -------- ----------------------------
C_IDVARCHAR2(2)
CNAME VARCHAR2(10)
SALARY NUMBER
C_ CNAME SALARY
-- ---------- ----------
c1jkjkjkj 7888