Dbms Lab Manual r20 Syllabus
Dbms Lab Manual r20 Syllabus
Regulation : R20
A.Y. : 2022-23
Mission:
M1: To impart value based technical education in CSE specific to AI & ML through
innovative teaching and learning methods.
M2: To produce outstanding professionals by imparting quality training, hands-on-
experience and value based education.
M3: To produce competent graduates suitable for industries and organizations at global
level including research and development for Social responsibility.
LAB CODE
Students should report to the concerned lab as per the time table.
Students who turn up late to the labs will in no case be permitted to do the program
schedule for the day.
After completion of the program, certification of the concerned staff in-charge in the
observation book is necessary.
Student should bring a notebook of 100 pages and should enter the readings /observations
into the notebook while performing the experiment.
The record of observations along with the detailed experimental procedure of the
experiment in the immediate last session should be submitted and certified staff member
in-charge.
The group-wise division made in the beginning should be adhered to and no mix up of
students among different groups will be permitted.
When the experiment is completed, should disconnect the setup made by them, and
should return all the components/instruments taken for the purpose.
Any damage of the equipment or burn-out components will be viewed seriously either by
putting penalty or by dismissing the total group of students from the lab for the
semester/year.
Students are required to prepare thoroughly to perform the experiment before coming to
laboratory.
INTRODUCTION
Database Management System
This model is like a hierarchical tree structure, used to construct a hierarchy of records in the
form of nodes and branches. The data elements present in the structure have Parent-Child
relationship. Closely related information in the parent-child structure is stored together as a
logical unit. A parent unit may have many child units, but a child is restricted to have only one
parent.
The drawbacks of this model are:
The hierarchical structure is not flexible to represent all the relationship proportions,
Which occur in the real world.
It cannot demonstrate the overall data model for the enterprise because of the non
availability of actual data at the time of designing the data model.
It cannot represent the Many-to-Many relationship.
Network Model
It supports the One-To-One and One-To-Many types only. The basic objects in this model are
Data Items, Data Aggregates, Records and Sets. It is an improvement on the Hierarchical Model.
Here multiple parent-child relationships are used. Rapid and easy access to data is possible in
this model due to multiple access paths to the data elements.
Relational Model
Does not maintain physical connection between relations
Data is organized in terms of rows and columns in a table
The position of a row and/or column in a table is of no importance
The intersection of a row and column must give a single value
Features of an RDBMS
The ability to create multiple relations and enter data into them
An attractive query language
Retrieval of information stored in more than one table
An RDBMS product has to satisfy at least seven of the 12 rules of Codd to be accepted as
a full- fledged RDBMS.
Roadway Travels
"Roadway Travels" is in business since 1997 with several buses connecting different places in
india. Its main office is located in Hydearabd.
Reservations are directly handled by booking office. Reservations can be made 30 days in
advance and tickets issued to passenger. One Passenger/person can book many tickets (to his/her
family).
In the process of computerization of Roadway Travels you have to design and develop a
Database which consists the data of Buses, Passengers, Tickets, and Reservation and cancellation
details. You should also develop query's usinf SQL to retrieve the data from database.
2. E-R Model
3. Relational Model
4. Normalization
6. Querying.
Students are suppossed to work on these steps week wise and finally create a complete "Database
System" to Roadway Travels. Examples are given at every experiment for guidance to students.
AIM :To Study And identify the entity in road way travels database
system
Analyze the problem carefully and come up with the entities in it. Identify what data has
to be persisted in the database. This contains the entities, attributes etc.
Entity:
An entity may be defined as a thing which is recognized as being capable of an
independent existence and which can be uniquely identified. An entity is an abstraction from the
complexities of some domain. When we speak of an entity we normally speak of some aspect of
the real world which can be distinguished from other aspects of the real world. Entities can be
thought of as nouns.
Examples:
A computer, an employee, a song, and a mathematical theorem.
Relationship:
A relationship captures how two or more entities are related to one another. Relationships
can be thought of as verbs, linking two or more nouns.
Examples:
An “owns” relationship between a company and a computer, a supervises relationship
between an employee and a department, a performs relationship between an artist and a song, a
proved relationship between a mathematician and a theorem.
Attributes:
Examples:
An employee entity might have a Social Security Number (SSN) attribute; the proved
relationship may have a date attribute.
1. Bus:
a. BUS NUMBER,
b. SOURCE,
c. DESTINATION.
d. NO OF DAYS AVAILBLE
2. Passenger:
a. PASSEBGER _ID
b. NAME,
c. AGE,
d. GENDER
e. ADDRESS
3. Ticket:
a. TICKET_ID
b. JOUTNEY_DATE
c. PNR NO
d. SOURCE
e. DESTINATION
f. BUS NO
4. Pastic
a. PID,
b. TID
1. Reservation:
a. PNRNO
b. JOUTNEY_DATE
c. NUMBER_OF_SEATS
2. Cancellation:
a. PNR _NO
b. JOUTNEY_DATE
c. NUMBER_OF_SEATS
d.
Primary keys:
Example:
A particular song is an entity. The collection of all songs in a
database is an entity set. The eaten relationship between a child and her
lunch is a single relationship. The set of all such child-lunch relationships in
a database is a relationship set. In other words, a relationship set corresponds
to a relation in mathematics, while a relationship corresponds to a member of
the relation.
Passe
No. days available nger_i
ddd
Pasgr id _ i
Address
Ticket_id
Ticket_id
Passenger_ID
PNR_No Source
Bus_n
o
Experiment 2
Aim : To perform the all the entities and relationships in tabular fashion
The relational models for the entities and relations are as follows:
Bus:
Bus_No Source Destination No of days available
Passenger:
P_ID NAME Age Gender Address Ticket_ID
Ticket:
Ticket_ID Journey_Date PNR_NO BUS_NO Source Destination
Reservation:
PNR_No Journey_Date No_of_seats
Cancellation:
PNR_No Journey_Date No_of_seats
Experiment 3
Normalization for database tables
AIM: To perform the normalization in a database system
4. BCNF
Passenger:
P_ID NAME Age Gender Address Ticket_ID
Passenger:
P_ID NAME Age Gender Address
Pastic
P_ID Ticket_ID
Experiment 4
Practicing DDL commands
DBMS Lab Manual
19
CMR Engineering College CSE-CSM
DDL COMMANDS
Definitions:
4. truncate: ‘truncate’ command truncates the table i.e. all the rows will
be deleted in the table.
Syntax: truncate table table-name;
5. drop: the ‘drop’ command deletes all information about the relation
from the database i.e. it deletes the schema of the relation.
Syntax: drop table table-name;
Creating tables:
5. Bus:
a. BUS NUMBER,
6. Passenger:
a. PASSEBGER _ID
b. NAME,
c. AGE,
d. GENDER
e. ADDRESS
7. Ticket:
a. TICKET_ID
b. JOUTNEY_DATE
c. PNR NO
d. SOURCE
e. DESTINATION
f. BUS NO
8. Pastic
a. PID,
b. TID
3. Reservation:
a. PNRNO
b. JOUTNEY_DATE
c. NUMBER_OF_SEATS
4. Cancellation:
a. PNR _NO
b. JOUTNEY_DATE
c. NUMBER_OF_SEATS
d.
Primary keys:
BUS Table:
SQL>desc BUS;
Passenger table:
TABLE CREATED.
Reservation Table:
SQL>DESC RESERVATION;
Cancellation Table:
SQL>DESC CANCELLATION;
Ticket Table:
SQL>desc TICKET;
To truncate a table:
To DROP a table:
Experiment 5
Practicing DML commands
DML COMMANDS
AIM: To study and execute all the DML commands in a
database system.
INSERT Command:
1 row created.
SQL> /
Enter value for busno: 5678
Enter value for source: guntur
Enter value for des: vizaq
old 1: insert into bus540 values('&busno','&source','&des')
new 1: insert into bus540 values('5678','guntur','vizaq')
1 row created.
SQL> /
Enter value for busno: 1345
Enter value for source: vinukonda
Enter value for des: guntur
old 1: insert into bus540 values('&busno','&source','&des')
new 1: insert into bus540 values('1345','vinukonda','guntur')
1 row created.
1 row updated.
1 row created.
SQL> /
Enter value for pid: 222
Enter value for name: sunay
Enter value for age: 11
Enter value for gender: m
Enter value for address: kcp
old 1: insert into passenger540
values('&pid','&name',&age,'&gender','&address')
new 1: insert into passenger540 values('222','sunay',11,'m','kcp')
1 row created.
SQL> /
Enter value for pid: 333
Enter value for name: nari
Enter value for age: 27
Enter value for gender: m
Enter value for address: guntur
old 1: insert into passenger540
values('&pid','&name',&age,'&gender','&address')
new 1: insert into passenger540 values('333','nari',27,'m','guntur')
1 row created.
Table created.
1 row created.
SQL> /
Enter value for tid: 223344
Enter value for journdate: 28-jul-13 9:30:33pm
Enter value for source: tirupathi
Enter value for destination: guntur
Enter value for busno: 1345
Enter value for pnrno: 114
old 1: insert into ticket1540
values(&tid,'&journdate','&source','&destination','&busno',&pnrno
)
new 1: insert into ticket1540 values(223344,'28-jul-13
9:30:33pm','tirupathi','guntur','1345',1
14)
1 row created.
SQL> /
Enter value for tid: 334455
Enter value for journdate: 29-mar-13 9:20:22pm
Enter value for source: manglore
Enter value for destination: hyd
Enter value for busno: 1234
Enter value for pnrno: 115
1 row created.
Table created.
1 row created.
1 row created.
1 row created.
SQL> select * from pastic;
TID PID
---------- ----------
112233 111
1223344 222
Table created.
1 row created.
SQL> /
Enter value for pnrno: 124
Enter value for date: 28-jul-2013
Enter value for noofseats: 2
old 1: insert into reservation540 values(&pnrno,'&date',&noofseats)
new 1: insert into reservation540 values(124,'28-jul-2013',2)
1 row created.
SQL> /
Enter value for pnrno: 111
Enter value for date: 29-mar-2013
Enter value for noofseats: 3
old 1: insert into reservation540 values(&pnrno,'&date',&noofseats)
new 1: insert into reservation540 values(111,'29-mar-2013',3)
1 row created.
Table created.
1 row created.
SQL> /
Enter value for pnrno: 111
1 row created.
SELECT Command:
SQL> SELECT * FROM BUS; (Selects all the attributes and display)
UPDATE Command:
Delete Command:
SQL> DELETE FROM BUS; (To delete entire rows from a table)
SQL> DELETE * FROM BUS WHERE bus_no=’boo1’; (To delete an
individual row)
Experiment 6
Querying (EXISTS, NOT EXIST, UNION, INTERSECT SET
OPERATIONS)
1. Union
2. Intersect
3. Except
4. Any
5. ALL
6. In
7.Avg
8.Min
9.Max
10.Sum
11.Count
Definitions:
EXISTS Operator:
The EXISTS sub query is used when we want to display all rows
where we have a matching column in both tables.
SQL> select name from passenger where exists (select * from ticket540
where tid='112233');
NAME
--------------------------------------------------
tarun
manu
deepak
shona
SQL> select name from passenger540 where exists (select * from ticket540
where tid='112233');
NAME
--------------------
ruchin
sunay
nari
SQL> select name from passenger540 where exists (select name from
ticket540
where tid='112233');
NAME
--------------------
ruchin
sunay
nari
NAME
--------------------
ruchin
NAME
--------------------
UNION Operator:
Combine the results of two SELECT statements into one result set,
and then eliminates and duplicate rows from that result set.
PID NAME
---------- --------------------
111 ruchin
222 sunay
333 nari
PID NAME
-------------------- --------------------
111 ruchin
222 sunay
333 nari
nari 333
ruchin 111
sunay 222
6 rows selected.
INTERSECT Operator:
Combine the results of two SELECT statements into one result set,
and returns only those rows that are returned by each of two statements.
Definitions:
The ANY Operator:the any operator allows you to specify multiple values
in a where clause and select any value from that list
The All Operator:the all operator allows you to specify multiple values in a
where clause and select all value from that list
ANY Operator:
ALL Operator:
IN Operator:
BETWEEN Operator
SQL> SELECT name FROM PASSENGER WHERE age
BETWEEN 30 AND 45;
5. Find the ticket numbers of the passengers whose name starts with
‘A’ and ends with ‘H’.
6. Find the names of all the passengers whose age is between 30 and
45.
1.Avg
2.Min
3.Max
4.Sum
5.Count
Definitions:
1. Sum: The input to sum must be a collection of numbers and it gives sum
of those numbers.
Experiment 7
Queries using GROUP BY, HAVING and Creation and droping of
VIEWS.
HAVING CLAUSE: The HAVING clause was added to SQL because the
WHERE keyword could not be used with aggregate functions.
SQL> select pnrno from reservation540 union select pnrno from cance540;
PNRNO
----------
111
123
124
Q)WAQ to find no of seats booked fro each pnrno using group by clause
PNRNO NOOFSEATS
---------- --------------
124 2
111 3
COUNT(DISTINCTSOURCE)
---------------------
1
PNRNO
----------
123
124
111
SUM(NOOFSEATS)
--------------
6
A view is, in essence, a virtual table. It does not physically exist. Rather, it is
created by a query joining one or more tables.
Creating VIEWS:
Dropping a View
Experiment 8
OUT PUT:
Experiment 9
OUT PUT:
Experiment 10
OUTPUT:
LEAD EXPERIMENTS