DBMS Lab Manual - 2024-25 3
DBMS Lab Manual - 2024-25 3
LABORATORY MANUAL
MCA, Semester -I
GALGOTIAS UNIVERSITY
SCHOOL OF COMPUTER APPLICATIONS &
TECHNOLOGY
Table of Contents
1. Vision and Mission of the University
2. Vision and Mission of the School
3. Programme Educational Objectives (PEOs)
4. Programme Outcomes (POs)
5. Programme Specific Outcomes (PSOs)
6. University Syllabus
7. Course Outcomes (COs)
8. Course Overview
9. List of Experiments
10. Lab assessment criteria
11. Guidelines for students for report preparation
Vision and Mission of the Institute
Vision
Mission
The mission of the department is to :
M1: Developing a strong foundation in fundamentals of computer applications with
responsiveness towards emerging technologies.
M2: Establishing state-of-the-art facilities and adopt education 4.0 practices to analyze,
develop, test and deploy sustainable ethical IT solutions by involving multiple stakeholders.
PEO1: be able to successfully pursue research in Computer Applications and allied disciplines
at institutions of transnational reputation.
PO1: An ability to independently carry out research /investigation and development work to
solve practical problems.
PO3: Students should be able to demonstrate a degree of mastery over the area as per the
specialization of the program. The mastery should be at a level higher than the requirements in
the appropriate bachelor program.
PROGRAM SPECIFIC OUTCOMES (PSOs)
PSO1: Have the ability to work with contemporary technologies in computing requisite to Industry
4.0 developing and implementing solutions to real life problems.
PSO2: Demonstrate application development skills learned through technical training and projects to
solve real world problems.
University Syllabus
Unit-1 Introduction to Database Management System
An overview of database management system, Database System Vs. File System, Database
system concepts and architecture, data models, schema and instances, data independence and
data base language and interfaces, Data definitions language, DML, Overall Database
Structure.
Unit-2 Entity Relationship Model
Conceptual Modelling of a database, The Entity-Relationship (ER) Model, Entity Types,
Entity Sets, Attributes, and Keys, Relationship Types, Relationship Sets, Weak Entity Types
Generalization, Specialization and Aggregation, Extended Entity Relationship (EER) Model.
Unit-3 Relational Model and SQL Query
Relational data model concepts, integrity constraints, entity integrity, referential integrity,
Keys constraints, and Domain constraints. Introduction to SQL: Characteristics of SQL,
advantage of SQL. SQL data type and literals. Types of SQL commands. SQL operators and
their procedure. Tables, views and indexes. Queries and sub queries. Aggregate functions.
Insert, update and delete operations, Joins, Unions, Intersection, Minus, Introduction to
PLSQL: Cursors, Triggers, and Procedures
Unit-4 Normalization
Functional dependencies, normal forms, first, second, third normal forms, BCNF, inclusion
dependence, loss less join decompositions, normalization using FD, MVD, and JDs
Unit-5 Overview of Transaction Management and Concurrency Control
Overview of Transaction Management: ACID Properties, Transactions and Schedules,
Concurrent Execution of transaction, Lock Based Concurrency Control, Performance
Locking Concurrency Control: Serializability, and recoverability, Introduction to Lock
Management, Lock Conversions, Dealing with Dead Locks, Specialized Locking
Techniques, Concurrency without Locking.
COURSE OBJECTIVE
To familiarize students with basic concepts of databases and database management systems
with emphasize on relational databases.
To gain a solid understanding of design the entity relationship diagram the database and the
concept of normalization also.
To explore and implement all the schemas on the SQL and PL/SQL platform which will give
the practical exposure to students in that they will learn how to create tables, manipulate table.
To understand the concepts of transactions and their processing in the real life scenario.
COURSE OUTCOMES(COs):
E1PA104B.1.1 Apply database design principles and structured query language (SQL) to
develop and manage databases.
E1PA104B.1.1 Analyze database models, including ER diagrams, to identify
normalization requirements and redundancy issues.
E1PA104B.1.1 Evaluate database transaction issues and propose effective solutions for
maintaining consistency and integrity in database management systems
E1PA104B.1.1 Apply SQL queries to create, manipulate, and manage data in a relational
database system.
COURSE ASSESSMENT
The course assessment patterns are the assessment tools used both in formative and summative
examinations.
Type of Final Marks
CIE Total Marks CIE*0.5+SEE*
Course (B)
0.5
LAB
LAB
Work@ + MTE CIE SEE
EXAM*
Record
INTEGRATED
25 50 25 100 100 100
*Passing Criteria-30% of marks to be secured in the lab Exam conducted by two examiners
(one internal and done external)
Assessment Criteria for Oracle Database Programming Lab
The assessment for each experiment will be based on the following criteria:
ASSIGNMENT- 1
Write various data types in SQL along with their description and syntax
Entity-Relationship Diagram:
Concept Draw gives the ability to describe a database using the Entity-Relationship model. Entity-
Relationship Diagram solution includes icons advocated by Chen's and Crow’s Foot notation that can be
used when describing a database. Concept Draw has examples and templates for Data Modeling with
Entity Relationship Diagram.
The ERD solution from ConceptDraw Solution Park extends ConceptDraw PRO vector graphics and
diagramming software with the ability to describe a database using the Entity-Relationship model. Use
ConceptDraw PRO enhanced with ERD solution to draw you own entity relationship diagrams using
Chen's or crow's foot notations.
ASSIGNMENT- 2
CREATE TABLE statement is used to create a table in a database. Tables are organized into rows and
columns; and each table must have a name.
The column_name parameters specify the names of the columns of the table. The data_type parameter
specifies what type of data the column can hold (e.g. varchar, integer, decimal, date, etc.). The size
parameter specifies the maximum length of the column of the table.
Example: Now we want to create a table called "Persons" that contains five columns: PersonID,
LastName, FirstName, Address, and City.
CREATE TABLE Persons
(
PersonID int, LastName varchar(255), FirstName varchar(255), Address varchar(255), City varchar(255)
);
INSERT INTO statement is used to insert new records in a table. It is possible to write the INSERT
INTO statement in two forms.
a) The first form does not specify the column names where the data will be inserted, only their values:
b) The second form specifies both the column names and the values to be inserted:
Create these two tables with following specifications and insert data in the table:
PRODUCT_MASTER
Using the table client master and product master answer the following queries:
(a) Delete the record of Client no. 0001 from the Client master table.
(b) Change the city of Client no. 0005 to ‘Bombay’.
(c) Change the balance due of Client no. 0002 to 1000.
(d) Find out the clients who stay in a city or state where second letter is a.
(e) Calculate the average balance due of all the clients.
(f) Change the selling price of 1.44 floppy drive to Rs. 1150.00.
(g) Count the number of products having price greater than or equal to 1500.
Objective: To Create and manage tables with constraints on it.
SQL constraints are used to specify rules for the data in a table. If there is any violation between the
constraint and the data action, the action is aborted by the constraint.
Constraints can be specified when the table is created (inside the CREATE TABLE statement) or after the
table is created (inside the ALTER TABLE statement).
DATA OF SALES_ORDER
The SQL RENAME command is used to change the name of the table or a database object.
If you change the object's name any reference to the old name will be affected. You have to manually
change the old name to the new name in every reference.
Syntax to rename a table
3) Add not null constraint in product master with columns : description, profit_percent, sellprice,
costprice
5) Add check constraint to product_master such that sellprice is always greater than costprice.
The GROUP BY statement is used in conjunction with the aggregate functions to group the result-set by
one or more columns.
Example
SELECT Shippers.ShipperName,COUNT(Orders.OrderID) AS NumberOfOrders FROM Orders
LEFT JOIN Shippers ON Orders.ShipperID=Shippers.ShipperID GROUP BY ShipperName;
We can also use the GROUP BY statement on more than one column, like this:
Example
SELECT Shippers.ShipperName, Employees.LastName, COUNT(Orders.OrderID) AS NumberOfOrders
FROM ((Orders INNER JOIN Shippers ON Orders.ShipperID=Shippers.ShipperID) INNER JOIN
Employees
ON Orders.EmployeeID=Employees.EmployeeID) GROUP BY ShipperName,LastName;
ASSIGNMENT- 7
1. Print the description and total quantity sold for each product.
2. Find the value of each product sold.
3. Find out the products which have been sold to ‘Ivan’.
4. Find the names of clients who have ‘CD Drive’.
5. Find the products and their quantities for the orders placed by ‘Vandana’ and ‘Ivan’
6. Select product_no, total_qty_ordered for each product.
7. Display the order number and day on which clients placed their order.
8. Display the month and date when the order must be delivered.
Objective: To implement join concepts
SQL JOIN clause is used to combine rows from two or more tables, based on a common field between
them.
The most common type of join is: SQL INNER JOIN (simple join). An SQL INNER JOIN return all
rows from multiple tables where the join condition is met.
Example
SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate FROM Orders INNER JOIN
Customers
ON Orders.CustomerID=Customers.CustomerID;
Before we continue with examples, we will list the types the different SQL JOINs you can use:
• INNER JOIN: Returns all rows when there is at least one match in BOTH tables
• LEFT JOIN: Return all rows from the left table, and the matched rows from the right table
• RIGHT JOIN: Return all rows from the right table, and the matched rows from the left table
• FULL JOIN: Return all rows when there is a match in ONE of the tables
ASSIGNMENT- 8
A Sub query or Inner query or Nested query is a query within another SQL query and embedded within
the WHERE clause. A sub query is used to return data that will be used in the main query as a condition to
further restrict the data to be retrieved. Sub queries can be used with the SELECT, INSERT, UPDATE,
and DELETE statements along with the operators like =, <, >, >=, <=, IN, BETWEEN etc.
• A sub-query can have only one column in the SELECT clause, unless multiple columns are in the
main query for the sub-query to compare its selected columns.
• An ORDER BY cannot be used in a sub-query, although the main query can use an ORDER BY.
The GROUP BY can be used to perform the same function as the ORDER BY in a sub-query.
• Sub-queries that return more than one row can only be used with multiple value operators, such as
the IN operator.
• The SELECT list cannot include any references to values that evaluate to a BLOB, ARRAY,
CLOB, or NCLOB.
• The BETWEEN operator cannot be used with a sub-query; however, the BETWEEN operator can
be used within the sub-query.
Sub-queries with the SELECT Statement: Sub-queries are most frequently used with the SELECT
statement. The basic syntax is as follows:
SELECT column_name [, column_name ] FROM table1 [, table2 ] WHERE column_name
OPERATOR
(SELECT column_name [, column_name ] FROM table1 [, table2 ] [WHERE])
ASSIGNEMENT-9
1. Find the product_no and description of non moving products.
2. Find the customer name, address, city and pincode for the client who has placed order no "019001".
3. Find the client name who have placed order before the month of may 2006.
4. Find out if product "1.44 Drive" is ordered by only client and print the client_no, name to whom it was
soled.
5. Find the name of client who have placed orders worth Rs. 10000 or more.
7. Select the name of person who are in Mr.Pradeep's department and who have also worked on inventory
control system.
8. Select all the clients and the slaesman in the city of Bombay.
9. Select slaesman name in Bombay who has atleast one client located at Bombay.
10. Select the product_no, description, qty_on-hand, cost_price of non_moving items in the
product_master table.
Objective: To implement concept of cursor
Oracle Engine uses a work area for its internal processing in order to execute an SQL statement. This
work area is private to SQL’s operations and is called a Cursor. The data that is stored in the cursor is
called the Active Data Set. The size of cursor in memory is the size required to hold the number of rows in
the Active Data Set which is determined by memory management capabilities of oracle and the amount of
RAM available. Oracle has a pre-defined area in main memory set aside, within which cursors are opened.
The values retrieved from a table are held in a cursor opened in memory by the oracle engine. This data is
then transferred to the client machine via the network. In order to hold this data, a cursor is opened. When
a cursor is loaded with multiple rows via a query , the Oracle engine opens and maintains a row pointer.
Depending on user’s requests to view data, the row pointer will be relocated within the cursor’s active
data set.
Types of Cursors: Cursors are classified into two categories depending on its circumstances under which
they are opened:
✓ Implicit Cursor
✓ Explicit Cursor
Implicit Cursor: If Oracle Engine opens cursor for its internal processing, it is known as Implicit Cursor.
When the SELECT…INTO or any DML statement is used (with respect to single row), the Oracle
internally opens the cursor, called as implicit cursor. Processing an implicit cursor is taken care of
automatically by PL/SQL.
Explicit Cursor: A cursor can be opened for processing data through a PL/SQL block, on demand. Such
a user defined cursor is known as Explicit Cursor. If a query returns more than one row then cursor has to
be defined explicitly. It is called as explicit cursor.
• SQL%ISOPEN cannot be referenced outside of its SQL statement, because Oracle engine
automatically opens and closes the SQL cursor after executing its associated select, insert, update
or delete statement has been processed. As a result, SQL%ISOPEN always returns to FALSE.
Create a explicit cursor which updates the salary of an employee such that,
1. If salary > 10000, then increase the salary by 15%
2. If 5000<salary <10000, then increase the salary by 12%
3. Otherwise, increase the salary by 25%
Solution:
Explicit Cursor:
DECLARE
CURSOR c1 IS SELECT empno, sal FROM emp WHERE deptno=10;
eno EMP.Empno%type;
salary EMP.Sal%type;
BEGIN
OPEN c1;
IF c1%ISOPEN THEN
LOOP
FETCH c1 into eno, salary;
Exit WHEN c1%NOTFOUND
IF salary > 10000 THEN
UPDATE EMP SET Sal = Sal*1.5 WHERE Empno=eno;
ELSIF salary BETWEEN 5000 and 10000 THEN
UPDATE EMP SET Sal = Sal*1.2 WHERE Empno=eno;
ELSE
UPDATE EMP SET Sal = Sal *2.5 WHERE Empno=eno;
END IF;
END LOOP;
CLOSE c1;
ELSE
DBMS_OUTPUT.PUT_LINE(‘Unable to Open the cursor’);
END IF;
END;
Objective: Creating procedure and functions in oracle.
Procedures:
Procedure is a subprogram that performs specific action. Like an unnamed or anonymous blocks, sub
programs have a declarative part, an executable part and an optional exception handling part.
SYNTAX
CREATE [OR REPLACE] PROCEDURE <procedure_name>
[(argument 1 [{IN | OUT | INOUT}] type,…….., argument2 [{IN | OUT | INOUT}] type)]
{IS | AS}
[local_variable_declarations;]
BEGIN
PL/SQL executable statements
[ EXCEPTION
Exception Handler;]
END <procedure_name>
FUNCTIONS:
• Functions are similar to stored procedures except they are always required to return a value.
• Both are having the same structure like declarative, executable and exception handling section.
• Like procedures, functions are also stored in the database. Generally we use functions to compute
a value.
• The syntax for creating function is very similar to the syntax for a procedure. It is as:
Ques 1. Create Procedure for modifying the salaries of employees from department number
10, such that:
1. If salary > 3000, then increase salary by 10%
2. If 2000<salary<3000, then increase the salary by 5%
3. Otherwise increase salary by 3%
Ques 2. Create a function for adding two numbers.
Calling Procedure
• When called, this procedure accepts an employee number, which it uses to find the basic salary of
that employee.
• If current employee is not found then it raises exception with a message otherwise salary will be
modified.
• Now the PL/SQL program to call this procedure may be as follow:
DECLARE
x EMP.Empno%type
CURSOR c1 is SELECT Empno FROM EMP WHERE Deptno=10;
BEGIN
OPEN c1;
LOOP
FETCH c1 INTO x;
Exit WHEN c1%notfound;
update_sal(x); //Call to procedure
END LOOP;
CLOSE c1;
END;
A trigger can include SQL and PL/SQL statements to execute as a unit and can invoke other stored
procedures. However, stored procedures and triggers differ in the following way.
(a) Triggers are implicitly executed by Oracle, when a table is modified – regardless of user or
applications acting on the table.
(b) A trigger can only be executed or fired by issuing any one of the INSERT, UPDATE or DELETE
action on a database table.
(c) Triggers do not accept arguments.
Table_reference: Triggering_reference is the name of the table for which the trigger is defined.
Triggering_condition: Triggering_condition specifies a Boolean expression that must be true for the
trigger to fire. The trigger action is not executed if the trigger_condition evaluates
to false. Trigger_condition is specified using a WHEN clause, which is optional.
Types of Triggers:
a) BEFORE trigger can be used in deciding whether we should permit a statement to complete.
b) AFTER triggers, on the other hand, validate the UPDATE, INSERT and DELETE operations after
they have taken place and allow rollback on exceptions raised.
c) FOR EACH ROW option determines whether the trigger is a row or statement trigger.
If we specify FOR EACH ROW, the trigger fires once for each row affected by the trigger.
Without this specification, the statement trigger fires once regardless of the number of rows affected.
Packages:
Packages are used to group logically related PL/SQL types, items and subprograms encapsulated into
single entity. This encapsulation creates a true business object with many interfaces, each one handling a
specific business task. When an object is called within a package, the entire package is loaded into
memory. This load is completed in one operation for each defined object in the package specification. As
a result, further reference to package requires no disk input/output, which speeds up the application
execution.
Package Specification
The package specification contains the information about the contents of the package. Here, the user can
declare data type, variables, constants, exceptions, and stored procedures (procedures and functions).
However, it does not contain any code for anything declared. The specification defines the package’s
interface to the calling applications and the users. The syntax for creating the package specification is
• PL/SQL objects declared in the package_specification are global, they can be called or used by
external users who have the specific privilege.
• The elements with the package specification (procedure, function etc) are the same as they would be in
the declarative section of a PL/SQL anonymous block. In specification, it is not necessary to have all
type of elements.
• A package can contain only procedures and functions without having any variables and other type of
elements.
Package body
1.Write PL/SQL statements for creating trigger which restricts any transaction on Sundays on transaction
table.
2.Create a package consisting of a procedure for updating the salary.
END emp_pack;
CREATE OR REPLACE BODY emp_pack
IS
PROCEDURE update_sal (eno IN NUMBER)
IS
x EMP. Empno % type
y EMP. Sal % type
BEGIN
SELECT empno, sal INTO x, y FROM emp WHERE empno=eno;
IF y> 3000 THEN
UPDATE EMP SET Sal= sal*1.1 WHERE Empno =eno;
ELSIF y between 2000 AND 3000 THEN
UPDATE EMP SET Sal= Sal*1.05 WHERE Empno =eno;
ELSE
UPDATE EMP SET Sal= Sal*1.03 WHERE Empno =eno;
END IF;
Calling a Package
Calling a package means actually referencing one of its elements. Following is the method for calling an
element from a package.
DECLARE
x VARCHAR2(20);
BEGIN
emp_pack.update_sal (7633);
END;
Student Report Format
Galgotias University
Plot No.2, Sector-17A, Yamuna Expresway, Greater
Noida, Gautam Buddh Nagar, U.P., India
Course
Name:_________________________________________________
Course Code:
_________________________________________________
School:_______________ Year:__________
Semester:________________
Program:___________________________
Session:___________________
Name:______________________________
____________________
Admission No:__________________
______________________________
__________________
__________
Name Semester Section Admission No.
Index
Sr. Name of Experiment Page Date of Signature of
No. No. Experiment Faculty
1. -------------------------------------------------------
2. -------------------------------------------------------
3. -------------------------------------------------------
4. -------------------------------------------------------
5. -------------------------------------------------------
6. -------------------------------------------------------
7. -------------------------------------------------------
8. -------------------------------------------------------
9.
-------------------------------------------------------
10.
-------------------------------------------------------
Experiment No. 1
Objective/Aim: (Write the objective here)
Sample Run: