Professional Documents
Culture Documents
UPD - DBMS Lab Manual-Final
UPD - DBMS Lab Manual-Final
UPD - DBMS Lab Manual-Final
APJ
GL BAJAJ
Institute of Technology & Management
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of Applied Computational Science & Engineering
Greater Noida
LAB MANUAL
ACADEMIC SESSION 2023-24
Understand and apply oracle 11 g for creating tables, views, indexes, sequences
KCS-551.1 and other database objects
Design and implement a database schema for company data base, banking data
KCS-551.2 base, library information system, payroll processing system, student information
System.
KCS-551.3 Write and execute simple and complex queries using DDL, DML, DCL and TCL.
Write and execute PL/SQL blocks, procedure functions, packages and triggers,
KCS-551.4 Cursors.
Enforce entity integrity, referential integrity, key constraints, domain
KCS-551.5 constraints on database.
CO-PO Matrix
Course
PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12
Outcomes
KCS-551.1 2 2 3 3 3 - - - - - - 2
KCS-551.2 3 3 3 2 2 - - - - - - 3
KCS-551.3 2 3 3 3 3 - - - - - - 2
KCS-551.4 2 3 2 2 2 - - - - - - 2
KCS-551.5 2 3 2 2 2 - - - - - - 3
CO-PSO Matrix
COs PSO1 PSO2
KCS-551.1 1 2
KCS-551.2 1 3
KCS-551.3 1 3
KCS-551.4 1 2
KCS-551.5 1 3
[Approved by AICTE, Govt. of India & Affiliated to Dr. APJ
GL BAJAJ
Institute of Technology & Management
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of Applied Computational Science & Engineering
Greater Noida
List of Experiments
S. No. Experiments
1 Installing Oracle
4 Normalization
Creating cursor
5
Creating procedure and functions
6
Experiment No: 1
Program Name: Installing Oracle
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
[Approved by AICTE, Govt. of India & Affiliated to Dr. APJ
GL BAJAJ
Institute of Technology & Management
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of Applied Computational Science & Engineering
Greater Noida
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.
[Approved by AICTE, Govt. of India & Affiliated to Dr. APJ
GL BAJAJ
Institute of Technology & Management
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of Applied Computational Science & Engineering
Greater Noida
5. Review the Summary window to verify what is to be installed. Then, click Install.
9. When the database has been created, you can unlock the users you want to use. Click OK.
Experiment No: 2
Steps:
In the diagram canvas, you can add entities by clicking on the "Entity" button in the toolbar and
then clicking on the canvas to place the entity.
Double-click on the entity to give it a name.
To add attributes to an entity, right-click on the entity and select "Add Attribute."
To define relationships between entities, select the "Relationship" tool from the toolbar.
Click on one entity and then click on the related entity to establish a relationship.
Specify the cardinality and other properties of the relationship.
Step 6: Save Your ERD
It's important to save your work. Click on "File" and then "Save" to save the model.
MySQL Workbench allows you to generate SQL scripts from your ERD. You can do this by
clicking on "Database" and then "Forward Engineer..." to create a database schema based on your
ERD.
Step 8: Review and Export (Optional)
You can review your ERD, make any necessary changes, and then export it in different formats,
such as PNG or PDF.
[Approved by AICTE, Govt. of India & Affiliated to Dr. APJ
GL BAJAJ
Institute of Technology & Management
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of Applied Computational Science & Engineering
Greater Noida
Output Examples:
[Approved by AICTE, Govt. of India & Affiliated to Dr. APJ
GL BAJAJ
Institute of Technology & Management
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of Applied Computational Science & Engineering
Greater Noida
[Approved by AICTE, Govt. of India & Affiliated to Dr. APJ
GL BAJAJ
Institute of Technology & Management
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of Applied Computational Science & Engineering
Greater Noida
[Approved by AICTE, Govt. of India & Affiliated to Dr. APJ
GL BAJAJ
Institute of Technology & Management
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of Applied Computational Science & Engineering
Greater Noida
[Approved by AICTE, Govt. of India & Affiliated to Dr. APJ
GL BAJAJ
Institute of Technology & Management
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of Applied Computational Science & Engineering
Greater Noida
[Approved by AICTE, Govt. of India & Affiliated to Dr. APJ
GL BAJAJ
Institute of Technology & Management
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of Applied Computational Science & Engineering
Greater Noida
[Approved by AICTE, Govt. of India & Affiliated to Dr. APJ
GL BAJAJ
Institute of Technology & Management
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of Applied Computational Science & Engineering
Greater Noida
Experiment No: - 3
-- Inner Join
SELECT orders.order_id, customers.customer_name
FROM orders
INNER JOIN customers ON orders.customer_id = customers.customer_id;
[Approved by AICTE, Govt. of India & Affiliated to Dr. APJ
GL BAJAJ
Institute of Technology & Management
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of Applied Computational Science & Engineering
Greater Noida
-- Left Join
SELECT employees.first_name, departments.department_name
FROM employees
LEFT JOIN departments ON employees.department_id = departments.department_id;
-- Deleting a record
DELETE FROM employees
WHERE employee_id = 102;
-- Dropping a table
DROP TABLE products;
[Approved by AICTE, Govt. of India & Affiliated to Dr. APJ
GL BAJAJ
Institute of Technology & Management
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of Applied Computational Science & Engineering
Greater Noida
Experiment No: - 4
Theory Concept:
Normalization is a database design process used to organize data in a relational database efficiently
and reduce data redundancy. It is a multi-step process that sets the data into tabular form and removes the
duplicated data from the relational tables. Normalization typically involves dividing a database into two or
more tables and defining relationships between them. Let's go through an example of normalizing a
database with sample data and MySQL queries. We'll start with an unnormalized table and normalize it
step by step.
We'll normalize the data by creating two separate tables: "Customers" and "Orders." The "Customers"
table will store customer information, and the "Orders" table will store order information.
Now that we have normalized our data, we can query the "Customers" and "Orders" tables to
retrieve information:
Output:
These queries demonstrate the result of normalizing the data. The "Customers" table contains
unique customer information, and the "Orders" table stores order details with a reference to the customer.
The last query retrieves the total order amount for each customer, demonstrating the power of relational
databases and normalization.
[Approved by AICTE, Govt. of India & Affiliated to Dr. APJ
GL BAJAJ
Institute of Technology & Management
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of Applied Computational Science & Engineering
Greater Noida
Experiment No-5
Implementation:
1. Declare Cursor
A cursor is a select statement, defined in the declaration section in MySQL.
Syntax
1. DECLARE cursor_name CURSOR FOR
2. Select statement;
Parameter:
cursor_name: name of the cursor
select_statement: select query associated with the cursor
2. Open Cursor
After declaring the cursor the next step is to open the cursor using open statement.
Syntax
Open cursor_name;
Parameter:
cursor_name: name of the cursor which is already declared.
3. Fetch Cursor
After declaring and opening the cursor, the next step is to fetch the cursor. It is used to fetch the row or the
column.
Syntax
FETCH [ NEXT [ FROM ] ] cursor_name INTO variable_list;
Parameter:
cursor_name: name of the cursor
variable_list: variables, comma separated, etc. is stored in a cursor for the result set
4. Close Cursor
The final step is to close the cursor.
Syntax
Close cursor_name;
Parameter:
Cursor_name: name of the cursor
[Approved by AICTE, Govt. of India & Affiliated to Dr. APJ
GL BAJAJ
Institute of Technology & Management
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of Applied Computational Science & Engineering
Greater Noida
[Approved by AICTE, Govt. of India & Affiliated to Dr. APJ
GL BAJAJ
Institute of Technology & Management
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of Applied Computational Science & Engineering
Greater Noida
[Approved by AICTE, Govt. of India & Affiliated to Dr. APJ
GL BAJAJ
Institute of Technology & Management
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of Applied Computational Science & Engineering
Greater Noida
Experiment No -6
Program Name: Creating procedure and functions in MYSQL
Theory Concept:
Let us understand how to create a procedure in MySQL through example. First, we need to select a
database that will store the newly created procedure. We can select the database using the below
statement:
Suppose this database has a table named student_info that contains the following data:
Implementation:
1. DELIMITER &&
2. CREATE PROCEDURE get_merit_student ()
3. BEGIN
4. SELECT * FROM student_info WHERE marks > 70;
5. SELECT COUNT(stud_code) AS Total_Student FROM student_info;
6. END &&
7. DELIMITER ;
Create Function
Just as you can create functions in other languages, you can create your own functions in
MySQL. Let's take a closer look.
Syntax
The syntax to create a function in MySQL is:
function_name
The name to assign to this function in MySQL.
[Approved by AICTE, Govt. of India & Affiliated to Dr. APJ
GL BAJAJ
Institute of Technology & Management
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of Applied Computational Science & Engineering
Greater Noida
parameter
One or more parameters passed into the function. When creating a function, all parameters
are considered to be IN parameters (not OUT or INOUT parameters) where the parameters
can be referenced by the function but can not be overwritten by the function.
return_datatype
The data type of the function's return value.
declaration_section
The place in the function where you declare local variables.
executable_section
The place in the function where you enter the code for the function.
Drop Function
Once you have created your function in MySQL, you might find that you need to remove it from the
database.
Syntax
The syntax to a drop a function in MySQL is:
function_name
The name of the function that you wish to drop.
Example
Let's look at an example of how to drop a function in MySQL.
For example:
Experiment No-7
Implementation:
Parameter Explanation
The create trigger syntax contains the following parameters:
trigger_name: It is the name of the trigger that we want to create. It must be written after the
CREATE TRIGGER statement. It is to make sure that the trigger name should be unique within the
schema.
trigger_time: It is the trigger action time, which should be either BEFORE or AFTER. It is the required
parameter while defining a trigger. It indicates that the trigger will be invoked before or after each row
modification occurs on the table.
trigger_event: It is the type of operation name that activates the trigger. It can be
either INSERT, UPDATE, or DELETE operation. The trigger can invoke only one event at one time. If
we want to define a trigger which is invoked by multiple events, it is required to define multiple triggers,
and one for each event.
table_name: It is the name of the table to which the trigger is associated. It must be written after the ON
keyword. If we did not specify the table name, a trigger would not exist.
BEGIN END Block: Finally, we will specify the statement for execution when the trigger is activated. If
we want to execute multiple statements, we will use the BEGIN END block that contains a set of queries
to define the logic for the trigger.
The trigger body can access the column's values, which are affected by the DML statement.
The NEW and OLD modifiers are used to distinguish the column values BEFORE and AFTER the
execution of the DML statement. We can use the column name with NEW and OLD modifiers
as OLD.col_name and NEW.col_name. The OLD.column_name indicates the column of an existing row
before the updation or deletion occurs. NEW.col_name indicates the column of a new row that will be
inserted or an existing row after it is updated.
[Approved by AICTE, Govt. of India & Affiliated to Dr. APJ
GL BAJAJ
Institute of Technology & Management
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of Applied Computational Science & Engineering
Greater Noida
For example, suppose we want to update the column name message_info using the trigger. In the trigger
body, we can access the column value before the update as OLD.message_info and the new
value NEW.message_info.
We can understand the availability of OLD and NEW modifiers with the below table:
Next, we will create a BEFORE INSERT trigger. This trigger is invoked automatically insert the
working_hours = 0 if someone tries to insert working_hours < 0.
[Approved by AICTE, Govt. of India & Affiliated to Dr. APJ
GL BAJAJ
Institute of Technology & Management
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of Applied Computational Science & Engineering
Greater Noida
Creating Packages:
Package Specification:
The specification is the interface to the package. It just DECLARES the types, variables, constants,
exceptions, cursors, and subprograms that can be referenced from outside the package. In other words, it
contains all information about the content of the package, but excludes the code for the subprograms.
All objects placed in the specification are called public objects. Any subprogram not in the package
specification but coded in the package body is called a private object.
The following program provides a more complete package. We will use the CUSTOMERS table stored
in our database with the following records –
[Approved by AICTE, Govt. of India & Affiliated to Dr. APJ
GL BAJAJ
Institute of Technology & Management
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of Applied Computational Science & Engineering
Greater Noida
When the above code is executed at the SQL prompt, it creates the above package and displays the
following result −Package created
[Approved by AICTE, Govt. of India & Affiliated to Dr. APJ
GL BAJAJ
Institute of Technology & Management
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of Applied Computational Science & Engineering
Greater Noida
The above example makes use of the nested table. We will discuss the concept of nested
table in the next chapter.
When the above code is executed at the SQL prompt, it produces the following result −
Experiment No: 8
Theory Concept:
1. Requirements Gathering:
Identify the specific requirements of your payroll system, including the types of employees, salary
structures, deductions, and reporting needs.
2. Database Design:
Create a MySQL database to store employee and payroll-related data. You can use tools like MySQL
Workbench for this task.
Set up relationships between tables using foreign keys to ensure data integrity.
Develop a user interface for data input, which allows HR personnel to add, edit, and delete employee
records.
Implement data validation to ensure that the entered data is accurate and consistent.
5. Salary Calculation:
Write SQL queries or create stored procedures to calculate employee salaries based on the salary structure
and allowances.
6. Deduction Management:
Create functions or stored procedures to manage deductions, including tax deductions, insurance, and
other deductions.
[Approved by AICTE, Govt. of India & Affiliated to Dr. APJ
GL BAJAJ
Institute of Technology & Management
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of Applied Computational Science & Engineering
Greater Noida
7. Payroll Processing:
Implement a payroll processing module that generates payroll records for each employee based on the pay
period.
8. Reporting:
9. Security:
Implement user authentication and authorization to restrict access to sensitive payroll data.
10. Testing:
Thoroughly test the system to ensure accuracy in salary calculations, data input, and report generation.
Implementation:
To implement a payroll processing system in MySQL, you'll need to create various tables to store employee
information, salary details, deductions, payroll records, and more. Below is an example of MySQL code to
create some of the essential tables for a basic payroll system. You can expand upon this schema to meet your
specific requirements:
MYSQL Code:
Experiment No: 9
Program Name: Write a CURSOR to display list of clientsintheCLIENT_MASTERtable.
Implementation:
DECLARE
CURSOR client_cur
isSELECT id,name,address
FROM client_master;
client_rec
client_cur%rowtype;BEGIN
OPENclient_cur;
LOOP
FETCH client_cur into
client_rec;EXITWHENclient_cur
%notfound;
DBMS_OUTPUT.put_line(client_rec.id||''||client_rec.name);
END LOOP;
END;
/
Output:Whenthe above codeis executed atSQLprompt,itproduces thefollowing result:
1 Ramesh
2 Khilan
3 kaushik
4 Chaitali
5 Hardik
6 Komal
Experiment No: 10
ProgramName:CreatingEntity-RelationshipDiagramusingcasetools.
Theory Concept: Entity relationship diagram (ERD) is a kind of diagram for presenting visually
thestructure of relational database. In this experiment we will make use of ERD to model the
databasestructure of a simple bus route management system.
Implementation:
1. StartVisualParadigm.Selectanewworkspacefolderforthistutorial.
2. SelectProject>Newfromthetoolbartocreateaproject.NametheprojectasBusRouteMa
nagement and confirm.
3. TocreateanERD,selectDiagram>Newfromthetoolbar.IntheNewDiagramwindow,selectEntityRel
ationship 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 tocreatean entity. Name theentityRoute and press Enterto confirm.
5. CreatecolumnsinRoute.Let'sstartwithaprimarykey.RightclickonentityRouteandselectNewCol
umn from popup menu.
6. Enter+id:varchar(10)andpressEnter.Notethatthe+signmeansthatthecolumnisaprimarykey.Varc
haris the columntype and 10 isthe length.
9. Release the mouse button and select Many-to-Many Relationship -> Entity from Resource Catalog.
NamethenewentityStop,YoucanseethatalinkedentityRoute_Stopisautomaticallycreatedinbetwee
n Route and Stop, with foreign key added.
12. A route has multiple bus schedules. Create an entity Schedule from Route with a one-to-
manyrelationship.MovethemousepointertoRoute.PressanddragouttheResourceCatalogicon.
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:
PK vehicle_id int(10)
[Approved by AICTE, Govt. of India & Affiliated to Dr. APJ
GL BAJAJ
Institute of Technology & Management
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of Applied Computational Science & Engineering
Greater Noida
fleet_id varchar(10)
last_main Date
16. A bus is driven by a bus driver. Create entity Driver from Bus with a one-to-one relationship. Add
thefollowing columns to Driver:
PK Id int(10)
Name varchar(255)
employ_date Date
[Approved by AICTE, Govt. of India & Affiliated to Dr. APJ
GL BAJAJ
Institute of Technology & Management
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of Applied Computational Science & Engineering
Greater Noida
Experiment No: 11
ProgramName: PL/SQLprogramming
a. WriteaPL/SQLblock codetoprintthe squaresofnumbersupto 99.
b. WriteaPL/SQLblockcodetoinsertdataintotableCUSTOMER
TheoryConcept:
Theprogramwouldprintthesquaresofnumbersupto99usingforloopanddataintotableCUSTOMERin
pl/sql.
Implementation:
Ans
(a):DECLARE
BEGIN
forxin1..99loop
dbms_output.put_l
ine(x*x);endloop;
end;
Output:
[Approved by AICTE, Govt. of India & Affiliated to Dr. APJ
GL BAJAJ
Institute of Technology & Management
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of Applied Computational Science & Engineering
Greater Noida
Implementation:
Ans:(b)
Null? Type
desc customer;Name
VARCHAR2(10)
C_IDVARCHAR2(2)CNAME
SALARY NUMBER
select*fromcustomer;
Output:
C_CNAME SALARY
c1jkjkjkj 7888
[Approved by AICTE, Govt. of India & Affiliated to Dr. APJ
GL BAJAJ
Institute of Technology & Management
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of Applied Computational Science & Engineering
Greater Noida
Experiment No-1
Program Name: Execute queries related to Exists, Not Exists, Union, Intersection,
Difference, Join
ontablesCLIENT_MASTER,PRODUCT_MASTER,SALESMAN_MASTER,SALES
_ORDER,SALES_ORDER_DETAILS
Theory Concept:
Theprogramretrievesdatafromrecordsbydefiningrelationbetweentwotablessoastoretrieve
filteredrecords.
Implementation:
Correlated queries with EXISTS/NOTEXISTS clause
Order_no Product_no
0002 05/feb/13
Order_no
0003
Output:
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: Selectnamefromclient_masterINTERSECT,selectnamefromsalesman_master;
Output:
No rows selected
Name
Akshita
Dhawal
Akansha
Divya
Dorothy
[Approved by AICTE, Govt. of India & Affiliated to Dr. APJ
GL BAJAJ
Institute of Technology & Management
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of Applied Computational Science & Engineering
Greater Noida
Client_no
6
7
5) Listalltheclientswhohavenotplacedanyorder.
Client_no
3
4
5
Client_no
3
4
5
7) FindalltheclientsandtheirnamesfromcityGhaziabadwhohavedeliverydateoftheirordersas
today.Ans:Select client_no from client_master where city=’Ghaziazbad’ INTERSECT
select client_no fromsales_order where delivery_date=’09-MAR-13’
Output:
Client_no
5
Queries on Joins
1) List the product_no and description of products sold.
Ans:Select product_no, description from (product1 natural join sales_order_details)
Output:
Product_no Description
1 Chair
1 Chair
[Approved by AICTE, Govt. of India & Affiliated to Dr. APJ
GL BAJAJ
Institute of Technology & Management
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of Applied Computational Science & Engineering
Greater Noida
2 Table
3 Sofa
Product_no Description
3 Sofa
3) Find the products and their quantities that will have to be delivered in the current
month.
Output:
Name
Akshita
Akansha
5)
6) List theorders forlessthan 5unitsof saleof‘chair’
Ans:Select product_no, order_no from (sales_order_details natural join
product1) where(description=’chair’and qty_ordered<5);
Output:
Product_no Order_no
1 0001
1 0001
[Approved by AICTE, Govt. of India & Affiliated to Dr. APJ
GL BAJAJ
Institute of Technology & Management
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of Applied Computational Science & Engineering
Greater Noida
Output :
8) Find the products and their quantities for the orders placed by the client_no ‘3’and ‘5’
Ans:Selectproduct_no,description,qty_orderedfrom(product1naturaljoinsales_order_det
ailsnaturaljoin 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
[Approved by AICTE, Govt. of India & Affiliated to Dr. APJ
GL BAJAJ
Institute of Technology & Management
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of Applied Computational Science & Engineering
Greater Noida
Experiment No: 2
TheoryConcept:ThefollowingexamplewouldillustratetheconceptofCURSORS.Wewillb
eusingthe CLIENT_MASTER table and display records.
Implementation:
DECLARE
CURSOR
client_cur
isSELEC
T
id,name,a
ddress
FROM
client_ma
ster;
client_r
ec
client_cur
%rowtype
;BEGIN
OPENclient_cur;
L
O
O
P
FETCH
client_cur into
client_rec;EXIT
WHENclient_cu
r%notfound;
DBMS_OUTPUT.put_line(client_rec.id||''
||client_rec.name);END LOOP;
END;
/
Output:Whenthe above codeis executed atSQLprompt,itproduces thefollowing result:
7 Ramesh
8 Khilan
9 kaushik
10 Chaitali
11 Hardik
[Approved by AICTE, Govt. of India & Affiliated to Dr. APJ
GL BAJAJ
Institute of Technology & Management
Abdul Kalam Technical University, Lucknow, U.P., India]
Department of Applied Computational Science & Engineering
Greater Noida
12 Komal