Professional Documents
Culture Documents
DBMS LAB Manual-2019-20 R18
DBMS LAB Manual-2019-20 R18
(AUTONOMOUS)
Department of Information Technology
II B. Tech II Semester
1
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
(AUTONOMOUS)
Department of Information Technology
PROGRAMMER : A. Sucharitha
Verified by :
Authorized by
HOD-IT
2
INDEX
S.No Contents
3 Department Goals
4 Lab Objective
5 Lab Outcomes
6 Evaluation Criteria
7 Guidelines to students
9 List of experiments
3
DEPARTMENT OF INFORMATION TECHNOLOGY
PEO 2: Graduates will have good communication skills, possess ethical conduct, sense of
responsibility to serve the society and protect the environment.
PEO 3: Graduates will have excellence in soft skills, managerial skills, leadership qualities and
understand the need for lifelong learning for a successful professional career.
4
10. 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.
11. 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.
12. 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.
● Nurture young individuals into knowledgeable, skillful and ethical professionals in their
pursuit of Information Technology.
● Transform the students through excellent teaching learning process and sustain high
performance by innovations.
● Extensive partnerships and collaborations with foreign universities.
● Develop industry-interaction for innovation and product development.
3. Department Goals
Long Term Goals
The Department Aims:
To introduce advanced interdisciplinary and vocational courses in curriculum.
To motivate members of faculty to attend workshops/conferences/training programs in
reputed organizations and publish quality research papers in recognized national and
international journals of repute.
To motivate members of faculty to improve their qualification and research skills.
To provide opportunities galore in the areas of research obtaining UGC/DST mini-major
projects.
To impart training sessions on quantitative aptitude, technical skills, group discussions
GRE, TOEFL, GATE for better placements.
To turn students industry ready to face relative practical problems in engineering
subjects.
5
To recruit well qualified and efficient faculty to impart state-of-art education and skills.
To enhance the ratio of doctorates contributing for research development.
To impart quality education and shape students as future leaders.
4. LAB OBJECTIVE
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”
The Student is expected to practice the designing, developing and querying a database in
the context of “Roadway Travels”.
The Student are expected to use “MySQL” Database for Practice.
5. LAB OUTCOME
CO2:Analyzing the business requirements and producing a viable model for the
implementation of the database
6
6. Evaluation Criteria
7. GUIDELINES TO STUDENTS
Students are required to carry their lab observation book and record book with completed
experiments while entering the lab.
Students must use the equipment with care. Any damage is caused student is punishable
Students are not allowed to use their cell phones/pen drives/ CDs in labs.
Students need to be maintain proper dress code along with ID Card
Students are supposed to occupy the computers allotted to them and are not supposed to talk or
make noise in the lab.
Students, after completion of each experiment they need to be updated in observation notes and
same to be updated in the record.
Lab records need to be submitted after completion of experiment and get it corrected with the
concerned lab faculty.
If a student is absent for any lab, they need to be completed the same experiment in the free time
before attending next lab.
8
Steps to perform experiments in the lab by the student
Step1: Students have to write the date, aim, and Software & Hardware requirements for that
experiment in the observation book.
Step2: Students have to listen and understand the experiment explained by the faculty and note
down the important points in the observation book.
Step3: Students need to write procedure/algorithm in the observation book.
Step4: Analyze and Develop/implement the logic of the program by the student in respective
platform
Step5: after approval of logic of the experiment by the faculty then the experiment has to be
executed on the system.
Step6: After successful execution the results are to be shown to the faculty and noted the same in
the observation book.
Step7: Students need to attend the Viva-Voce on that experiment and write the same in the
observation book.
Step8: Update the completed experiment in the record and submit to the concerned faculty in-
charge.
Instructions to maintain the record
Before start of the first lab they have to buy the record and bring the record to the lab.
Regularly (Weekly) update the record after completion of the experiment and get it
corrected with concerned lab in-charge for continuous evaluation.
In case the record is lost inform the same day to the faculty in charge and get the new
record within 2 days the record has to be submitted and get it corrected by the faculty.
If record is not submitted in time or record is not written properly, the evaluation marks
(5M) will be deducted.
There are 65 systems (Acer) installed in this Lab. Their configurations are as follows:
9
Students can execute ETL process using this tool. They can import the Meta data from
different source definition into the data warehouse by applying the business logics.
Students can generate reports using this tool from different Business Objects in different
formats.
Students can execute their assembly language programs using MASM. MASM is very
useful students because when they execute their programs they can see contents of
Processor Registers and how each instruction is being executed in the CPU.
Rational Rose Software is installed in some systems
Using this software, students can depict UML diagrams of their projects.
Softwares installed: C, C++, JDK1.5, MASM, OFFICE-XP, J2EE and DOT-NET,
Rational Rose.
Systems are provided for students in the 1:1 ratio.
Systems are assigned numbers and same system is allotted for students when they do the
lab.
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
10
9. List of Experiments
1. Analyze the problem carefully and come up with the entities in it.
5. Identify the other keys like candidate keys, partial keys, if any.
11
Week1: Entity Relationship (E-R Model)
Aim: Analyze the problem and come with the entities in it. Identify what data has to be
Persisted in the databases.
Hardware Requirements: Intel Based desktop PC with minimum of 166 MHZ or faster
processor with at least 1GB RAM and 500 MB free disk space.
MySQL 5.6.1
Prerequisites: Student must know the entities and attributes and representation of diagrams
Bus
- BusNo
- Source
- Destination
- CoachType
Passenger
- PassportID
- Name
- Age
- Sex
- Address
Ticket
- TicketNo
- DOJ
- Age
- Sex
- Source
- Destination
- BusNo
12
Reservation
- PNRNo
- DOJ
- ContactNo
- No_of_seats
- BusNo
- Address
Cancellation
- PNRNo
- DOJ
- No_of_seats
- Status
Conclusion: The Student is able to identify the Entities and Attributes of the
Roadway Travels
Viva-Voce:
1. What is SQL?
3. What is DBMS?
4. What is a Database system?
5. Advantages of DBMS?
6. How many types of database languages are available?
13
2.Concept design with E-R Model
Aim: To Relate the entities appropriately. Apply cardinalities for each relationship.
Identify strong and weak entities. Indicate the type of relationships (total/partial).
Incorporate generalization, aggregation and specialization etc wherever required.
Hardware Requirements: Intel Based desktop PC with minimum of 166 MHZ or faster
processor with at least 1GB RAM and 500 MB free disk space.
MySQL 5.6.1
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:
3. Relational Model
Aim: To Represent all the entities (Strong, Weak) in tabular fashion. Represent
relationships in a tabular fashion.
Hardware Requirements: Intel Based desktop PC with minimum of 166 MHZ or faster
processor with at least 1GB RAM and 500 MB free disk space.
MySQL 5.6.1
Ticket:
15
Passenger:
Reservation:
16
Key
SeatNo Integer Simple
Cancellation:
Conclusion: The Student is able draw the tabular representation of the relations of
Roadway travels.
Viva-Voce:
17
4. What is VIEW ? and What will you get when you use VIEW
4.Normalization
Aim: Apply the database Normalization techniques for designing relational database
tables to minimize duplication of information like 1NF, 2NF, 3NF, BCNF.
Hardware Requirements: Intel Based desktop PC with minimum of 166 MHZ or faster
processor with at least 1GB RAM and 500 MB free disk space.
MySQL 5.6.1
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.
Source varchar(20),
Destination varchar(20),
coachType varchar(10),
18
PRIMARY KEY(BusNo));
Name varchar(20),
Age integer,
Sex varchar,
Address varchar(20),
ContactNo Varchar(12),
PRIMARY KEY(PassportID));
Dept_Time varchar(10),
PRIMARY KEY(TicketNo));
PRIMARY KEY(PassportID,TicketNo),
DOJ date,
No_of_seats int(2),
Address varchar(20),
ContactNo Varchar(10),
19
Status varchar(10),
PRIMARY KEY(PNR_NO));
DOJ Date,
No_of_Seats integer(2),
Address varchar(20),
ContactNo integer(12),
Status varchar(10),
Viva-Voce:
1. Define Normalization?
4. What is 2NF?
5. What is 3NF?
Aim: Installation of MySQL. Creating database tables, altering the database, dropping
tables and truncate commands
Hardware Requirements: Intel Based desktop PC with minimum of 166 MHZ or faster
processor with at least 1GB RAM and 500 MB free disk space.
20
MySQL 5.6.1
Step1: Make sure you already downloaded the MySQL essential 5.0.45 win32.msi file. Double
click on the .msi file.
Step2: This is MySQL Server 5.0 setup wizard. The setup wizard will install MySQL Server 5.0
release 5.0.45 on your computer. To continue, click next.
Step3: 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.
Step4: 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.
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. To continue, click next.
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.
Step11: 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.
Source varchar(20),
Destination varchar(20),
coachType varchar(10),
PRIMARY KEY(BusNo));
Table Created
Name varchar(20),
Age integer,
Sex varchar,
22
Address varchar(20),
ContactNo Varchar(12),
PRIMARY KEY(PassportID));
Table Created
Dept_Time varchar(10),
PRIMARY KEY(TicketNo));
Table Created
PRIMARY KEY(PassportID,TicketNo),
Table Created
DOJ date,
No_of_seats int(2),
Address varchar(20),
ContactNo Varchar(10),
Status varchar(10),
PRIMARY KEY(PNR_NO));
Table Created
23
6. Mysql>Create table Cancellation(PNR_No integer(10),
DOJ Date,
No_of_Seats integer(2),
Address varchar(20),
ContactNo integer(12),
Status varchar(10),
Table Created
Field Datatype
BusNo varchar(10),
Source varchar(20),
Destination varchar(20),
CoachType varchar(10),
Capacity integer(2)
24
Mysql> TRUNCATE TABLE BUS;
Conclusion: The Student is able Install the MySQL and Create database, Create
tables and Alter tables.
Viva Voce:
Aim : Create a DML Commands are used to manage data within the scheme objects.
Hardware Requirements: Intel Based desktop PC with minimum of 166 MHZ or faster
processor with at least 1GB RAM and 500 MB free disk space.
MySQL 5.6.1
DML Commands:
26
sql>Insert into Passenger values(82302,’Smith’,23,’M’,’Hyderabad’,’9982682829’);
PassportID TicketNo
8738939 453
5443243 332
28
Mysql> DELETE FROM BUS WHERE BusNo=’AP345’;
Conclusion: The Student is able perform DML Commands like Insert, Update, Delete
and Select
Viva-Voce
29
4. Write the syntax for delete command?
5. Write the syntax for select command?
6. Difference between DCL and TCL
7.Querying
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
PNR_No
783-32923
928-38983
30
2. Display all the names of male passengers.
Name
Smith
John
31
3. Display the ticket numbers and names of all the passengers.
4. Find the ticket numbers of the passengers whose name start with ‘r’ and ends with ‘h’.
Name
Rajesh
Ramesh
32
5. Find the names of Passengers whose age is between 30 and 45.
Name
neha
Ramu
33
MySQL> SELECT * FROM PASSENGER WHERE NAME LIKE ‘A%’;
Name
Akash
Avinash
Arivind
Name
Akash
Aravind
Avinash
Neha
Ramu
smith
34
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?
8. Querying
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.
35
Recommended Hardware / Software Requirements:
Hardware Requirements: Intel Based desktop PC with minimum of 166 MHZ or faster
processor with at least 1GB RAM and 500 MB free disk space.
MySQL 5.6.1
1. Write a Query to display the information present in the passenger and cancellation
tables
UNION
36
PNR_N DOJ No_of_S Addre ContactNo Status
O EATS ss
7839344 2003-03- 5 Hyder 9440121444 cnfirm
5 04 abad
7839393 2003-03- 4 Hyder 9440121232 Cnfirm
0 04 abad
7839344 2003-03- 2 Hyder 938837383 Cnfirm
5 04 abad
7839344 2003-03- 4 Hyder 938837383 cnfirm
5 04 abad
MINAGE
23
37
3. Find number of tickets booked for each PNR_No using GROUP BY CLAUSE
PNR_NO SUM_OF_SEATS
78393445 5
78393930 4
PNR_NO
78393445
78393930
SUM(NO_OF_SEATS)
----------------
6
39
Viva-Voce:
9. Querying
5. Find the number of tickets booked by a passenger where the number of seats is
greater than 1.
6. Find the total number of cancelled seats.
Hardware Requirements: Intel Based desktop PC with minimum of 166 MHZ or faster
processor with at least 1GB RAM and 500 MB free disk space.
MySQL 5.6.1
40
5. Find the number of tickets booked by a passenger where the number of seats is
greater than 1.
CANCELLATION;
CANCELLED_SEATS
03
41
Conclusion: The Student is able to execute the Queries using SQL Clauses
10.Triggers
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
42
i) CREATE TABLE BUS_AUDIT1(ID INT NOT NULL AUTO_INCREMENT,
SOURCE
DELIMITER $$
43
CREATE TRIGGER BEFORE_BUS_UPDATE
BEGIN
SET action='update',
source=OLD.source,
changedon=NOW();
END$$
i)UPDATE :
44
SNo Source Changedon Action
1 Banglore 2014:03:23 12:51:00 Insert
2 Kerela 2014:03:25:12:56:00 Update
3 Mumbai 2014:04:26:12:59:02 Delete
ii) INSERT:
BEGIN
SET action='Insert',
source=NEW.source,
changedon=NOW();
END$$
45
SNo Source Changedon Action
1 Banglore 2014:03:23 12:51:00 Insert
2 Kerela 2014:03:25:12:56:00 Update
3 Mumbai 2014:04:26:12:59:02 Delete
iii)
BEGIN
SET action='Insert',
source=NEW.source,
changedon=NOW();
END$$
46
SNo Source Changedon Action
1 Banglore 2014:03:23 12:51:00 Insert
2 Kerela 2014:03:25:12:56:00 Update
3 Mumbai 2014:04:26:12:59:02 Delete
Conclusion: The Student is able to work on Triggers and create active database.
Viva-Vice:
1. What is TRIGGER?
11.Procedures
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
Ex1:
END$$
CALL BUS_PROC1()$$
Ex2:
BEGIN
DECLARE X INT(3);
SET X=10;
SELECT X;
48
END$$
CALL SAMPLE2()$$
BEGIN
END$$
CALL SIMPLE_PROC(@a)$$
PARAM1
4
49
Viva Voce:
12.Cursors
Aim: Declare a cursor that defines a result set. Open the cursor to establish the result set.
Fetch the data into local variables as needed from the cursor, one row at a time. Close the
cursor when done.
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
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
50
Fetch the 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.
Example :In the following example first of all we have to declare the Cursor and select the all
records from Company table. And after opened the cursor we fetch the record one by one from
cursor. And then insert these record in Products table
delimiter $$
CREATE PROCEDURE DemoCurs()
BEGIN
DECLARE d INT DEFAULT 0;
DECLARE c_id INT;
DECLARE c_name,c_address VARCHAR(20);
DECLARE cur CURSOR FOR SELECT * FROM company;
DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET d=1;
DECLARE CONTINUE HANDLER FOR SQLSTATE '23000' SET d=1;
OPEN cur;
lbl: LOOP
51
IF d=1 THEN
LEAVE lbl;
END IF;
IF NOT d=1 THEN
FETCH cur INTO c_id,c_name,c_address;
INSERT INTO products VALUES(c_id,c_name,c_address);
END IF;
END LOOP;
CLOSE cur;
END$$
mysql> delimiter ;
mysql> CALL DemoCurs();
Query OK, 1 row affected (0.12 sec)
52
Conclusion: The Student is able to work on Cursors.
Viva Voce:
1. What is a cursor?
53
54