Mr22 Dbms Lab Manual
Mr22 Dbms Lab Manual
(CSE)
II B. Tech II Semester
Applicable for the students of B.Tech. (Regular) programme admitted from the Academic Year 2022
onwards
The B.Tech. Degree of Jawaharlal Nehru Technological University Hyderabad, Hyderabad shall be
conferred on candidates who are admitted to the programme and who fulfill all the requirements for the
award of the Degree.
VISION OF THE INSTITUTE
To be a premier center of professional education and research, offering quality programs in a socio-
economic and ethical ambience.
MISSION OF THE INSTITUTE
To impart knowledge of advanced technologies using state-of-the-art infrastructuralfacilities.
To inculcate innovation and best practices in education, training and research.
To meet changing socio-economic needs in an ethical ambience.
DEPARTMENT VISION
To attain global standards in Computer Science and Engineering education, training and research to meet the
growing needs of the industry with socio-economic and ethical considerations.
DEPARTMENT MISSION
To impart quality education and research to undergraduate and postgraduate students in Computer
Science and Engineering..
To encourage innovation and best practices in Computer Science and Engineering utilizing state-of-
the-art facilities.
To develop entrepreneurial spirit and knowledge of emerging technologies based on ethical values
and social relevance.
PROGRAMME EDUCATIONAL OBJECTIVES (PEOs)
PEO1: To impart with a sound knowledge in scientific and engineering technologies necessary to
formulate, analyze, design and implement solutions to computer technology related problems.
PEO2: To carry out research in frontier areas of computer science and engineering with the capacity to
learn independently throughout life to develop new technologies.
PEO3: To train to exhibit technical, communication and project management skills in their profession and
follow ethical practices.
PEO4: To possess leadership and team working skills to become a visionary and an inspirational leader and
entrepreneur.
PROGRAMME OUTCOMES (POs)
PO1: Engineering knowledge: Apply the knowledge of mathematics, science, engineering fundamentals,
and an engineering specialization to the solution of complex engineering problems.
PO2: Problem analysis: Identify, formulate, review research literature and analyze complex engineering
problems reaching substantiated conclusions using first principles of mathematics, natural sciences, and
engineering sciences.
PO3: Design/development of solutions: Design solutions for complex engineering problems and design
system components or processes that meet the specified needs with appropriate consideration for the public
health and safety, and the cultural, societal, and environmental considerations.
PO4: Conduct investigations of complex problems: Use research-based knowledge and research methods
including design of experiments, analysis and interpretation of data, and synthesis of the information to
provide valid conclusions.
PO5: Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern
engineering and IT tools including prediction and modeling to complex engineering activities with an
understanding of the limitations.
PO6: The engineer and society: Apply reasoning informed by the contextual knowledge to assess societal,
health, safety, legal and cultural issues and the consequent responsibilities relevant to the professional
engineering practice.
PO7: Environment and sustainability: Understand the impact of the professional engineering solutions in
societal and environmental contexts, and demonstrate the knowledge of, and need for sustainable
development.
PO8: Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms of
the engineering practice.
PO9: Individual and team work: Function effectively as an individual and as a member or leader in
diverse teams, and in multidisciplinary settings.
PO10: Communication: Communicate effectively on complex engineering activities with the engineering
community and with society at large, such as, being able to comprehend and write effective reports and
design documentation, make effective presentations, and give and receive clear instructions.
PO11: Project management and finance: Demonstrate knowledge and understanding of the engineering
and management principles and apply these to one’s own work, as a member and leader in a team, to
manage projects and in multidisciplinary environments.
PO12: Life-long learning: Recognize the need for, and have the preparation and ability to engage in
independent and life-long learning in the broadest context of technological change.
PSO1: The ability to identify, analyze real world problems and design their ethical solutions using
computer-based systems of varying complexity.
PSO2: The ability to design and develop the hardware and interfacing software systems for solving real
world engineering problems with socio acceptance.
PSO3: The ability to employ modern computer languages, and platforms in creating innovative career paths
to be an entrepreneur by inculcating in them moral values & ethics.
Database Management Systems Lab
Lab Syllabus:
2022-23
MALLA REDDY ENGINEERING COLLEGE B.Tech.
Onwards
(Autonomous) IV Semester
(MR-22)
Code: C0519 Database Management Systems Lab L T P
(Common for CSE, CSE (Cyber Security), CSE (AI and
Credits: 1 ML), CSE (DS), CSE (IOT), AI and IT) - - 2
Co-requisites: “Database Management Systems”
Course Objectives:
1. Introduce ER data model, database design and normalization
2. Learn SQL basics for data definition and data manipulation
Course Outcomes:
1. Design database schema for a given application and apply normalization
2. Acquire skills in using SQL commands for data definition and data manipulation.
3. Develop solutions for database applications using procedures, cursors and triggers
LIST OF EXPERIMENTS:
i) Concept design with E-R Model
ii) Relational Model
iii) Normalization
iv) Practicing DDL commands
v) Practicing DML commands
vi) A. Querying (using ANY, ALL, UNION, INTERSECT, JOIN, Constraints etc.)
B. Nested, Correlated subqueries
vii) Queries using Aggregate functions, GROUP BY, HAVING and Creation and dropping ofViews.
viii) Triggers (Creation of insert trigger, delete trigger, update trigger)
ix) Procedures
x) Usage of Cursors
TEXT BOOKS:
1. Database Management Systems, Raghurama Krishnan, Johannes Gehrke, Tata Mc Graw Hill, 3rdEdition
2. Database System Concepts, Silberschatz, Korth, McGraw Hill, V edition.
REFERENCE BOOKS:
1. Database Systems design, Implementation, and Management, Peter Rob & Carlos Coronel 7thEdition.
2. Fundamentals of Database Systems, Elmasri Navrate, Pearson Education
3. Introduction to Database Systems, C.J. Date, Pearson Education
4. Oracle for Professionals, The X Team, S. Shah and V. Shah, SPD.
5. Database Systems Using Oracle: A Simplified guide to SQL and PL/SQL, Shah, PHI.
6. Fundamentals of Database Management Systems, M. L. Gillenson, Wiley Student Edition.
PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12 PSO1 PSO2 PSO3
COs
CO1 2 - -
CO2 - 2 2 1 2
CO3 2 2 2 3 2 2
1. LAB OBJECTIVES
This DBMS Lab enables the students to practice the concepts learnt in the DBMS
subject by developing a database for an example company named “Roadway Travels”
2. LAB OUTCOMES
Upon successful completion of this Lab the student will be able to:
ER Model: The Objective of the lab is to analyze the problem carefully and come up
with entities and attributes etc in the Roadway Travels and later buildup the conceptual
design with the E-R Model.
Relational Model: The Objective of the lab exercise is to represent all the entities in
tabular fashion, representing relationships as tables based on Cardinality, different types
of attributes(composite, Multi-valued and Derived)
Installation of MySQL and Practicing DDL & DML commands: The Objective of the
lab Exercise is to install the MySQL software and Practice DDL & DML Commands and
Practicing the Queries.
Triggers, Cursors and Procedures: The Objective of the lab exercise is to create
triggers and cursors and writing Procedures on Roadway Travels database
INDEX
S. No Name of the Experiment Date Page Sign
No
1. Concept design with E-R Model
2. Relational Model
3. Normalization
4. Practicing DDL commands
5. Practicing DML commands
6.A Querying (using ANY, ALL,
UNION, INTERSECT, JOIN,
Constraints etc.)
B. Nested, Correlated subqueries
7. Queries using Aggregate functions,
GROUP BY, HAVING and Creation
and dropping of Views.
8. Triggers (Creation of insert trigger,
delete trigger, update trigger)
9. Procedures
Prerequisites: Student must know the entities and attributes and representation of
diagrams The Following are the entities:
Identify the primary keys for all the entities. Identify the other keys like candidate keys,
partial keys, if any.
Example:
Entities: 1. BUS
2. Ticket
3. Passenger
Relationships: 1. Reservation
2. Cancellation
E-R Model
Bus
- BusNo
- Source
- Destination
- CoachType
SCHEMA
Ticket
- TicketNo
- DOJ
- Address
- ContactNo
- BusNo
- SeatNo
- Source
- Destination
SCHEMA
Passenger
- PassportID
- TicketNo
- Name
- ContactNo
- Age
- Sex
- Address
SCHEMA
Reservation
- PNRNo
- DOJ
- No_of_seats
- Address
- ContactNo
- BusNo
- SeatNo
SCHEMA
Reservation(PNRNo: String, DOJ: Date, NoofSeats: integer , Address: String ,ContactNo:
String, , BusNo: String,SeatNo:Integer)
Cancellation
- PNRNo
- DOJ
- SeatNo
- ContactNo
- Status
SCHEMA
Conclusion: The Student is able to Identify the Entities and Attributes of the
Roadway Travels
Viva-Voce:
1. What is SQL?
2. what is entity and relationship?
3. What is DBMS?
4. What is a Database system?
5. Advantages of DBMS?
6.How many types of database languages are available?
Prerequisites: Student must know the entities and attributes and relationship among entities
Conclusion: The Student is able design the concept design of Road-way Travels
Viva-Vice:
Aim: To Represent all the entities (Strong, Weak) in tabular fashion. Represent
relationships in a tabular fashion.
Mysql>desc Bus;
Ticket:
Mysql>desc Ticket;
Passenger:
Type of
ColumnName Datatype Constraints Attributes
PassportID Varchar(15) Primary Key Single-valued
TicketNo Varchar(20) Foreign Key Single-valued
Name Varchar(20) Composite
ContactNo Varchar(20) Multi-valued
Age Integer Single-valued
Sex character Simple
Address Varchar(20) Composite
Reservation:
Cancellation:
Conclusion: The Student is able draw the tabular representation of the relations of
Roadway travels.
Viva-Voce:
2. What is VIEW ? and What will you get when you use VIEW
WEEK 3 : NORMALIZATION
Aim: Apply the database Normalization techniques for designing relational database
tables to minimize duplication of information like 1NF, 2NF, 3NF, BCNF.
1NF: A Relation scheme is said to be in 1NF if the attribute values in the relation are
atomic.i.e., Mutli –valued attributes are not permitted.
2NF: A Relation scheme is said to be in 2NF,iff and every Non-key attribute is fully
functionally dependent on primary Key.
3NF: A Relation scheme is said to be in 3NF,iff and does not have transitivity
dependencies. A Relation is said to be 3NF if every determinant is a key for each & every
functional dependency.
BCNF: A Relation scheme is said to be BCNF if the following statements are true for eacg
FD P->Q in set F of FDs that holds for each FD. P->Q in set F of FD’s that holds over R.
Here P is the subset of attributes of R & Q is a single attribute of R.
3NF Viva-Voce:
3. Define Normalization?
6. What is 2NF?
7. What is 3NF?
Step 3
Choose the setup type that best suits your needs. For common program features select Typical
and it’s recommended for general use. To continue, click next.
Step 4
This wizard is ready to begin installation. Destination folder will be in C:\Program Files\
MySQL\MySQL Server 5.0\. To continue, click next
Step5
The program features you selected are being installed. Please wait while the setup wizard
installs MySQL 5.0. This may take several minutes.
Step6
To continue, click next.
Step7
To continue, click next
Step8
Wizard Completed. Setup has finished installing MySQL 5.0. Check the configure the MySQL
server now to continue. Click Finish to exit the wizard
Step9
The configuration wizard will allow you to configure the MySQL Server 5.0 server instance
Step10
Select a standard configuration and this will use a general purpose configuration for the
server that can be tuned manually. To continue, click next
Step 11
Check on the install as windows service and include bin directory in windows path. To
continue, click next.
Step12
Please set the security options by entering the root password and confirm retype the password.
To continue, click next.
Step13
Ready to execute? Clicks execute to continue.
Step14
Processing configuration in progress.
Step 15
Configuration file created. Windows service MySQL5 installed. Press finish to close the wizard.
Viva Voce:
Aim : Create a DML Commands are used to manage data within the scheme
DML Commands:
Conclusion: The Student is able perform DML Commands like Insert, Update, Delete
and Select
Viva-Voce
RESERVATION2
Reservation;
PNR_No
10201
10202
10203
10204
4. Find the ticket numbers of the passengers whose name start with ‘r’ and ends with ‘h’.
Name
Rajesh
Ramesh
Ramesh
Name
Akash
Arivind
Avinash
8. JOINS
Create a table EMP with the following structure.
Queries:
Display all the employees and the departments implementing a left outer join.
Display the employee name and department name in which they are working implementing a full outer join.
// MySQL does not support full outer join out of the box, unlike other databases.
Display all employee names and salary whose salary is greater than minimum salary of the
companyand job titlestarts with ‘M’.
Write a query to display information about employees who earn more than any employee in dept 30.
Inserting more values:
Query:
To drop a view:
Constraints
SQL constraints are used to specify rules for the data in a table.
Constraints can be column level or table level. Column level constraints apply to a column, and
table level constraints apply to the whole table.
The following SQL ensures that the "ID", "LastName", and "FirstName" columns will NOT accept
NULL values when the "Persons" table is created:
To create a NOT NULL constraint on the "Age" column when the "Persons" table is already created,
use the following SQL:
MySQL:
To name a UNIQUE constraint, and to define a UNIQUE constraint on multiple columns, use the
following SQL syntax:
To create a UNIQUE constraint on the "ID" column when the table is already created, use the
following SQL:
Primary keys must contain UNIQUE values, and cannot contain NULL values.
The following SQL creates a PRIMARY KEY on the "ID" column when the "Persons" table is
created:
MySQL:
A FOREIGN KEY is a field (or collection of fields) in one table, that refers to the PRIMARY
KEY in another table.
Persons Table
1 Hansen Ola 30
2 Svendson Tove 23
3 Pettersen Kari 20
Orders Table
1 77895 3
2 44678 3
3 22456 2
4 24562 1
Notice that the "PersonID" column in the "Orders" table points to the "PersonID" column in the
"Persons" table.
The "PersonID" column in the "Persons" table is the PRIMARY KEY in the "Persons" table.
The "PersonID" column in the "Orders" table is a FOREIGN KEY in the "Orders" table.
The FOREIGN KEY constraint prevents invalid data from being inserted into the foreign key
column, because it has to be one of the values contained in the parent table.
The following SQL creates a FOREIGN KEY on the "PersonID" column when the "Orders" table
is created:
MySQL:
The CHECK constraint is used to limit the value range that can be placed in a column.
If you define a CHECK constraint on a column it will allow only certain values for this column.
The following SQL creates a CHECK constraint on the "Age" column when the "Persons" table is
created. The CHECK constraint ensures that the age of a person must be 18, or older:
MySQL:
The default value will be added to all new records, if no other value is specified.
The following SQL sets a DEFAULT value for the "City" column when the "Persons" table is
created:
The DEFAULT constraint can also be used to insert system values, by using functions
like GETDATE():
Indexes are used to retrieve data from the database more quickly than otherwise. The users cannot
see the indexes, they are just used to speed up searches/queries.
The SQL statement below creates an index named "idx_lastname" on the "LastName" column in
the "Persons" table:
If you want to create an index on a combination of columns, you can list the column names within
the parentheses, separated by commas:
Conclusion: The Student is able execute the Queries from above database.
Viva-Vice:
1. What is the result of String functions?
4. What is Concatenation?
Nested Queries
A query embedded in a query. This type of relation is termed as Nested Query and the Embedded
Query is termed as a subquery.
Example
SQL_Correlated_Subqueries
A correlated subquery is evaluated once for each row processed by the parent statement. The parent statement
can be a SELECT, UPDATE, or DELETE statement.
A correlated subquery is one way of reading every row in a table and comparing values in each row
against related data. It is used whenever a subquery must return a different result or set of results for each
candidate row considered by the main query. In other words, you can use a correlated subquery to answer a
multipart question whose answer depends on the value in each row processed by the parent statement.
Use a correlated subquery to update rows in one table based on rows from another table.
CORRELATED DELETE :
DELETE FROM table1 alias1
WHERE column1 operator
(SELECT expression
FROM table2 alias2
WHERE alias1.column = alias2.column);
Use a correlated subquery to delete rows in one table based on the rows from another table.
OUTPUT :
These types of queries are nested queries which are independent or depend only on the same row of an
outer query being an embedded query.
Example
There are different types of set comparison operators like EXISTS, IN and UNIQUE. SQL also
supports op ANY and op ALL, where op means arithmetic comparison operators such
as <, <=, =, <>, >=, >. SOME are also one of the set comparison operators but it is similar to ANY.
Example
Aim: To Practice Queries using Aggregate functions, group by, having and dropping views for
the following
1. Write a Query to display the information present in the passenger and cancellation
tables
2. Display the number of days in a week on which the AP123 bus is available
3. Find number of tickets booked for each PNR_No using GROUP BY CLAUSE
4. Find the distinct PNR Numbers that are present.
1. Write a Query to display the information present in the passenger and cancellation
tables
UNION
3. Find number of tickets booked for each PNR_No using GROUP BY CLAUSE
1. Find the number of tickets booked by a passenger where the number of seats is
greater than 1.
2. Find the total number of cancelled seats.
Find the number of tickets booked by a passenger where the number of seats is
greater than 1.
mysql> create table students(sid int primary key,name varchar(15),login varchar(15), age int,gpa real);
mysql> create view Goodstudents(sid,gpa) AS select s.sid,s.gpa from students s where gpa > 3.0;
Viva-Voce:
Hardware Requirements: Intel Based desktop PC with minimum of 166 MHZ or faster
processor with at least 64MB RAM and 100 MB free disk space.
MySQL 5.6.1
DELIMITER $$
BEGIN
SET action='update',
source=OLD.source,
changedon=NOW();
END$$
i)UPDATE :
ii) INSERT:
CREATE TRIGGER
ON BUS
BEGIN
SET action='Insert',
source=NEW.source,
changedon=NOW();
END$$
iii)
BEGIN
SET action='Insert',
source=NEW.source,
changedon=NOW();
END$$
Examples
BEGIN
ELSE
SET New.TicketNo = 0;
END IF;
END;
database. Viva-Vice:
1. What is TRIGGER?
WEEK 9: Procedures
Aim: Creation of stored Procedures and Execution of Procedures and Modification of
Procedures.
Ex1:
BEGIN
END$$
CALL BUS_PROC1()$$
Ex2:
BEGIN
DECLARE X
SELECT X;
END$$
BEGIN
END$$
Mysql> CALL
SIMPLE_PROC(@a)$$Mysql> select
@a;
Viva Voce:
Cursors
In MySQL, a cursor allows row-by-row processing of the result sets. A cursor is used for the
result set and returned from a query. By using a cursor, you can iterate, or by step through the
results of a query and perform certain operations on each row. The cursor allows you to iterate
through the result set and then perform the additional processing only on the rows that require it.
In a cursor contains the data in a loop. Cursors may be different from SQL commands that
operate on all the rows in the returned by a query at one time.
Declare a cursor
1 . Declaration of Cursor : To declare a cursor you must use the DECLARE statement. With
the help of the variables, conditions and handlers we need to declare a cursor before we can use
it. first of all we will give the cursor a name, this is how we will refer to it later in the procedure.
We can have more than one cursor in a single procedure so its necessary to give it a name that
will in some way tell us what its doing. We then need to specify the select statement we want to
associate with the cursor. The SQL statement can be any valid SQL statement and it is possible
to use a dynamic where clause using variable or parameters as we have seen previously.
2 . Open a cursor statement : For open a cursor we must use the open statement.If we want
to fetch rows from it you must open the cursor.
3 . Cursor fetch statement : When we have to retrieve the next row from the cursor and
move the cursor to next row then you need to fetch the cursor.
If any row exists, then the above statement fetches the next row and cursor pointer moves ahead
to the next row.
Syntax: CLOSE_name;
By this statement we can close the previously opened cursor. If it is not closed explicitly then a
cursor is closed at the end of compound statement in which that was declared.
Delimiter $$
Viva Voce:
1. What is a cursor?
ADDITIONAL PROGRAMMS
EMPLOYEES TABLE
DEPARTMENT TABLE
Mysql> Create table Sailors(Sid integer PRIMARY KEY,sname varchar(15), rating int,age real);
mysql> select S.sname from sailors S, reserves R where S.sid=R.sid AND R.bid=103;
mysql> select sname from sailors s,Reserves R where S.sid=R.sid AND bid=103;
mysql> select R.sid from Boats B,Reserves R where B.bid=R.bid AND B.color='red';
mysql> select S.sname from sailors S,reserves R,Boats B where S.sid=R.sid AND R.bid=B.bid
AND B.color='red';
mysql> select B.color from Sailors S,Reserves R,Boats B where S.sid=R.sid AND R.bid=B.bid
AND S.sname='Lubber';
where 2*S1.rating=S2.rating-1;
1).Find the names of sailors who have reserved a red or a green boat.
OR
2). Find the names of sailors who have reserved both a red and a green boat.
SELECT S.SNAME
FROM SAILORS S,RESERVES R,BOATS B
WHERE S.SID=R.SID AND R.BID=B.BID AND B.COLOR='red'
INTERSECT
SELECT S2.SNAME
FROM SAILORS S2,RESERVES R2,BOATS B2
WHERE S2.SID=R2.SID AND R2.BID=B2.BID AND B2.COLOR='green';
NESTED QUERIES
Find the names of Sailors who have NOT reserved a red Boat
Find sailors whose rating is better than some sailor called Horatio
Sailors S2);
Find the age of the youngest sailor for each rating level.
Find the age of the youngest sailor who is eligible to vote for each rating level with at least two
such sailors
For each red boat , find the number of reservations for this boat
Find the average age of sailors for each rating level that has at least two sailors