Sie sind auf Seite 1von 54

GURU NANAK INSTITUTIONS TECHNICAL CAMPUS

(AUTONOMOUS)
Department of Information Technology

Database Management Systems


Master Lab Manual
Subject Code: 18PC0IT09
For the Academic year 2019-20

II B. Tech II Semester

Guru Nanak Institutions Technical Campus


Ibrahimpatnam, R R District – 501 506 (T. S.)

1
GURU NANAK INSTITUTIONS TECHNICAL CAMPUS
(AUTONOMOUS)
Department of Information Technology

LAB MANUAL FOR THE ACADEMIC YEAR 2019-20

SUB : Database Management Systems

SUB CODE : 18PC0IT10


SEMESTER : II
STREAM : IT
Document No : GNITC/IT/ DBMS/Auto
Date of Issue : 16-12-19
Date of Revision : 16-12-19
Prepared : N.Siva Rama Krishna Prasad

PROGRAMMER : A. Sucharitha

Verified by :

Authorized by

Dr. Thariq Hussan

HOD-IT

2
INDEX
S.No Contents

1 Programme Educational Objectives & Programme Outcomes

2 Department Vision & Mission

3 Department Goals

4 Lab Objective

5 Lab Outcomes

6 Evaluation Criteria

7 Guidelines to students

8 Introduction About Lab

9 List of experiments

10 List of Additional Experiments

11 Text Books / Reference Books

3
DEPARTMENT OF INFORMATION TECHNOLOGY

1.PROGRAMME EDUCATIONAL OBJECTIVES (PEOs)


PEO 1: Produce industry ready graduates having the ability to apply academic knowledge across
the disciplines and in emerging areas of Information Technology for higher studies, research,
employability, product development and handle the realistic problems.

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.

PROGRAMME OUTCOMES (POs)


Engineering Graduates will be able to:

1. Engineering knowledge: Apply the knowledge of mathematics, science, engineering


fundamentals, and an engineering specialization to the solution of complex engineering
problems.
2. 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.
3. 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.
4. 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.
5. 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.
6. 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.
7. 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.
8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and
norms of the engineering practice.
9. Individual and team work: Function effectively as an individual, and as a member or leader
in diverse teams, and in multidisciplinary settings.

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.

PROGRAMME SPECIFIC OUTCOMES (PSOs)


1. Ability to design, develop, test and debug software applications, evaluate and recognize
potential risks and provide innovative solutions.

2. Explore technical knowledge in diverse areas of Information Technology for upliftment of


society, successful career, entrepreneurship and higher studies.

2. VISION OF THE DEPARTMENT

To be a premier Information Technology department in the region by providing high quality


education.

MISSION OF THE DEPARTMENT

● 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.

Short Term Goals


The Department Aims:
 To impart fundamental knowledge in Basic Sciences and Humanities viz., Physics,
Chemistry, Mathematics, Environmental Science and Communicative English.
 To fine tune the students to inculcate social and professional ethics.
 To contribute to the all round development of students by providing extensive counseling
and mentoring in terms of academics and career oriented problems.
 To inculcate systematic approach to practical learning.
 To provide hands on experience of teaching learning process.
 To create self learning ambience to widen students’ basic skills exposing them to
advanced topics.
 To motivate the members of faculty to enrich state-of-art pedagogic skills in guiding the
students to accomplish their goals.
 To impart effective facilitation in classical as well as modern principles for better results.
 To motivate the students towards curricular and extra-curricular activities.
 To impart effective communication and soft skills to develop competent outlook.

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

CO1:Design an ER diagram for a real time application

CO2:Analyzing the business requirements and producing a viable model for the
implementation of the database

CO3:Converting the entity-relationship diagrams into relational tables

CO4:Develop appropriate databases to a given problem that integrates ethical, social,


legal, and economic concerns

CO5:Implement queries using SQL commands

6
6. Evaluation Criteria

a) Awarding the marks for day to day evaluation


Total marks for day to day evaluation is 15 marks as per JNTUH.
These 15 marks are distributed as:
Record 5 marks
Exp setup/program
5 marks
written and execution
Result and Viva-Voce 5 marks

b) Allocation of Marks for Lab Internal


Total marks for lab internal are 30 marks.
These 30 marks are distributed as:
Average of day to day evaluation: 15 marks
Lab Mid-Exam : 10 marks
Attendance : 5 marks.

c) Allocation of Marks for Lab External


Total marks for lab external are 70 marks.
These 50 marks are distributed as:
Program Written : 20 marks
Program Execution and Result:15 marks
Observations/ Calculations and
Record : 15 marks
Viva-Voce : 20 marks

7. GUIDELINES TO STUDENTS

A. STANDARD OPERATING PROCEDURE


a) Explanation on today’s experiment by the concerned faculty using PPT covering the following
aspects:
1) Name of the experiment
2) Aim
3) Software/Hardware requirements
4) Commands with suitable Options
5) Creating Database
1) Altering database
2) Querying
3) Dropping database
b) Writing of DDL and DML commands by the students
7
c) Querying and executing of the SQL queries 100 mins.

Writing of the experiment in the Observation Book


The students will write the today’s experiment in the Observation book as per the
following format:
a) Name of the experiment
b) Aim
c) Software/Hardware required
d) Commands with suitable Options
e) SQL Queries
f) Creating Database
a. Altering database
b. Querying
c. Dropping database
g) Results for different Queries
h) Viva-Voce Questions and Answers
i) Errors observed (if any) during compilation/execution
j) Signature of the Faculty

B. Guide Lines to Students in Lab

Disciplinary to be maintained by the students in the Lab

 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.

8. INTRODUCTION ABOUT LAB

There are 65 systems (Acer) installed in this Lab. Their configurations are as follows:

 Hardware / Software’s installed: Intel® CORE™ i3-3240 CPU@3.40GHZ RAM:4GB /


C, C++ Compiler
 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.
 All systems are configured in DUAL BOOT mode i.e., Students can boot from Windows
XP or Linux as per their lab requirement. This is very useful for students because they are
familiar with different Operating Systems so that they can execute their programs in
different programming environments.
 Each student has a separate login for database access MySQL client version is installed in
all systems. On the server, account for each student has been created. This is very useful
because students can save their work (scenarios’, PL / SQL programs, data related
projects, etc) in their own accounts. Each student work is safe and secure from other
students.

 ETL TOOL: Informatica 7.1.1 is installed in all the systems.

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.

 Reporting TOOL: COGONS is installed in all the systems.

Students can generate reports using this tool from different Business Objects in different
formats.

 MASM (Macro Assembler) is installed in all the systems

 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)

 Normalization: The Objective of the lab exercise is to apply the Normalization


techniques like INF,2NF,3NF,BCNF to above Roadway travels database

 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

Week1 Entity Relationship(E-R Model)

1. Analyze the problem carefully and come up with the entities in it.

2. Identify what data has to be persisted in the database.

3. This contains the entities, attributes etc.

4. Identify the primary keys for all the entities.

5. Identify the other keys like candidate keys, partial keys, if any.

Week2 Concept design with E-R Model


Week3 Relational Model
Week4 Normalization
Week5 Installation of MYSQL and practicing DDL commands
Week6 Practicing DML commands
Week7 Queries using ANY, ALL, IN, Exists, NOT EXISTS, UNION, INTERSECT,
Constraints.
Week8 & Queries using Aggregate functions (COUNT, SUM, AVG, and MAX and
Week9 MIN), GROUP BY, HAVING and Creation and dropping of Views.
Week10 Triggers In this week you are going to work on Triggers. Creation of insert
trigger, delete trigger, update trigger. Practice triggers using the above database.
Week11 Procedures In this session you are going to learn Creation of stored procedure,
Execution of procedure and modification of procedure. Practice procedures
using the above database
Week12 Cursors In this week you need to do the following: 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.

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.

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

Prerequisites: Student must know the entities and attributes and representation of diagrams

The Following are the entities:


1 .Bus
2. Reservation
3. Ticket
4. Passenger
5. Cancellation

Attributes of the following Entities

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

The Schemes for the following entities are:

1. Bus(BusNo String, Source String, Destination String, Coach_Type String);


2. Passenger(PassportID String, Name String, Age integer, Sex character, Address
String);
3. Ticket(TicketNo Integer, DOJ date, Age integer, Dept_time Timestamp, Source
String, Destination String, BusNo String);
4. Reservation(PNRNo String, DOJ Date, ContactNo Integer, No_of_Seats integer,
BusNo String, Address String);
5. Cancellation(PNRNo String,DOJ Date, SeatNo integer,ContactNo integer,Status
String);

Conclusion: The Student is able to identify the Entities and Attributes of the
Roadway Travels

Viva-Voce:

1. What is SQL?

2. Is it Case Sensitive or non Case Sensitive?

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.

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

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:

1. Describe the three levels of data abstraction?

2. Define the "integrity rules"

3. What are the usage of SQL?

4. What is the use of SELECT?

5. What is the difference between UNION and INTERSECT?

6. Does SQL support programming?

3. Relational Model

Aim: To Represent all the entities (Strong, Weak) in tabular fashion. Represent
relationships in a tabular fashion.

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

Prerequisites: Student must know about the Relational Model


14
Bus:

ColumnName Datatype Constraints Type of Attributes


BusNo Varchar(10) Primary Single-valued
Key
Source Varchar(20) Single-valued
Destination Varchar(20) Simple
CouchType Varchar(10) Simple

Ticket:

ColumnName Datatype Constraints Type of Attributes


TicketNo Integer Primary Key Single-valued
DOJ Date Single-valued
Address Varchar(20) Composite
ContactNo Integer Multi-valued
BusNo Varchar(10) Foreign Key Single-valued
SeatNo Integer Simple
Source Varchar(10) Simple
Destination Varchar(10) Simple

15
Passenger:

ColumnName Datatype Constraints Type of


Attributes
PassportID Varchar(15) Primary Key Single-valued
TicketNo Integer Foreign Key Single-valued
Name Varchar(20) Composite
ContactNo Integer Multi-valued
Age Integer Single-valued
Sex Varchar Simple
Address Varchar(20) Composite

Reservation:

ColumnName Datatype Constraints Type of Attributes


PNRNo Interger Primary Single-valued
Key
DOJ date Single-valued
No_of_Seats Integer Simple
Address Varchar(20) Composite
ContactNo Integer Multi-valued
BusNo Varchar(10) Foreign Single-valued

16
Key
SeatNo Integer Simple

Cancellation:

ColumnName Datatype Constraints Type of Attributes


PNRNo Interger Primary Key Single-valued
DOJ date Single-valued
SeatNo Integer Simple
ContactNo Varchar(10) Multi-valued
Status Varchar(10) Simple

Conclusion: The Student is able draw the tabular representation of the relations of
Roadway travels.

Viva-Voce:

1. What is the difference between SUM and COUNT ?

2. What will you get when you use MIN ?

3. What will you get when you use MAX ?

17
4. What is VIEW ? and What will you get when you use VIEW

5. What is difference between TRUNCATE and DELETE?

4.Normalization

Aim: Apply the database Normalization techniques for designing relational database
tables to minimize duplication of information like 1NF, 2NF, 3NF, BCNF.

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

Prerequisites: Student must know about the Relational database(SQL)

Normalization is a process of converting a relation to be standard form by decomposition a


larger relation into smaller efficient relation that depicts a good database design.

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.

i) The given FD is a trival

ii) P is a super key.

1. Create table Bus(BusNo varchar(10) NOT NULL,

Source varchar(20),

Destination varchar(20),

coachType varchar(10),
18
PRIMARY KEY(BusNo));

2. Create table Passenger(PassportID varchar(15) NOT NULL,

Name varchar(20),

Age integer,

Sex varchar,

Address varchar(20),

ContactNo Varchar(12),

PRIMARY KEY(PassportID));

3. Create table Ticket(TicketNo integer(10), NOT NULL,

DOJ date, Age integer(2), Sex Varchar,

Source varchar(20), Destination varchar(20),

Dept_Time varchar(10),

PRIMARY KEY(TicketNo));

4. Create table Passenger_Ticket(PassportID varchar(15) NOT NULL,

TicketNo integer(10) NOT NULL,

PRIMARY KEY(PassportID,TicketNo),

FOREIGN KEY(PassportID) REFERENCES Passenger(PassportID),

FOREIGN KEY(TicketNo) REFERENCES Ticket(TicketNo));

5. Create table Reservation(PNR_No integer(10) NOT NULL,

DOJ date,

No_of_seats int(2),

Address varchar(20),

ContactNo Varchar(10),

19
Status varchar(10),

PRIMARY KEY(PNR_NO));

6. Create table Cancellation(PNR_No integer(10),

DOJ Date,

No_of_Seats integer(2),

Address varchar(20),

ContactNo integer(12),

Status varchar(10),

FOREIGN KEY(PNR_No) REFERENCES Reservation(PNR_No));

Conclusion: The Student is able to Normalize the tables applying 3NF

Viva-Voce:

1. Define Normalization?

2. What is 1 NF (Normal Form)?

3. What is Fully Functional dependency?

4. What is 2NF?

5. What is 3NF?

6. What is BCNF (Boyce-Codd Normal Form)?

5.Installation of MySQL and Practicing DDL Commands

Aim: Installation of MySQL. Creating database tables, altering the database, dropping
tables and truncate commands

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.

20
 MySQL 5.6.1

Prerequisites: Student must know about the MySQL

Steps for Installation of MySQL:

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.

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. 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.

Step13: Ready to execute? Clicks execute to continue

Step14: Processing configuration in progress


21
Step15: Configuration file created. Windows service MySQL5 installed. Press finish to close the
wizard.

Creating Tables and altering the Tables

1. Mysql>Create table Bus(BusNo varchar(10) NOT NULL,

Source varchar(20),

Destination varchar(20),

coachType varchar(10),

PRIMARY KEY(BusNo));

Table Created

2. Mysql>Create table Passenger(PassportID varchar(15) NOT NULL,

Name varchar(20),

Age integer,

Sex varchar,

22
Address varchar(20),

ContactNo Varchar(12),

PRIMARY KEY(PassportID));

Table Created

3. Mysql>Create table Ticket(TicketNo integer(10), NOT NULL,

DOJ date, Age integer(2), Sex Varchar,

Source varchar(20), Destination varchar(20),

Dept_Time varchar(10),

PRIMARY KEY(TicketNo));

Table Created

4. Mysql>Create table Passenger_Ticket(PassportID varchar(15) NOT NULL,

TicketNo integer(10) NOT NULL,

PRIMARY KEY(PassportID,TicketNo),

FOREIGN KEY(PassportID) REFERENCES Passenger(PassportID),

FOREIGN KEY(TicketNo) REFERENCES Ticket(TicketNo));

Table Created

5. MySql>Create table Reservation(PNR_No integer(10) NOT NULL,

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),

FOREIGN KEY(PNR_No) REFERENCES Reservation(PNR_No));

Table Created

ADD COLUMN CAPACITY to BUS Table

MySql> ALTER TABLE BUS ADD CAPACITY Integer(2);

Mysql> desc bus;

Field Datatype
BusNo varchar(10),
Source varchar(20),
Destination varchar(20),
CoachType varchar(10),
Capacity integer(2)

24
Mysql> TRUNCATE TABLE BUS;

Deletes all the fields of the table

Conclusion: The Student is able Install the MySQL and Create database, Create
tables and Alter tables.

Viva Voce:

1. What is DDL (Data Definition Language)?


2. What is VDL (View Definition Language)?
3. What is SDL (Storage Definition Language)?
25
4. What is DML (Data Manipulation Language)?
5. What is DML Compiler?
6. What is PL/SQL?

6. Practicing DML Commands

Aim : Create a DML Commands are used to manage data within the scheme objects.

SELECT- retrieve data from the database


INSERT- insert data into a table
UPDATE- Updates existing data within a table
DELETE-delete all records from a table.

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

Prerequisites: Student must know about the RDBMS SQL

DML Commands:

Mysql>Insert into Bus values(‘AP123’,’Hyderabad’,’Banglore’,’Volvo’);

MySql>Insert into Bus values(‘AP234’,’Mumbai’,’Hyderabad’,’Semi-sleeper’);

Insert 5 or more records like-wise

Mysql> Select * from Bus;

BusNo Source Destination CoachType


AP123 Hyderabad Banglore Volvo
AP234 Mumbai Hyderabad Semi-Sleeper

26
sql>Insert into Passenger values(82302,’Smith’,23,’M’,’Hyderabad’,’9982682829’);

Insert 5 or more records like-wise

Mysql> Select * from Passenger;

PassPortID Name Age Se Address ContactNo


x
8939034 Smith 23 M Hyderab 983893023
ad
9820023 John 24 M Mumbai 983893093
30
8738939 Kavitha 22 F Hyderab 998383673
ad 23

Mysql> Insert into Passenger_Ticket values(‘AP123’,82302);

Insert 5 or more records like-wise

Mysql> Select * from Passenger_Ticket;

PassportID TicketNo
8738939 453
5443243 332

Mysql> Insert into Ticket values(29823,’AP123’,82302,’21-03-2014’,’4:00PM’,


27
‘98202030334’);

Insert 5 or more records like-wise

TicketNo BusNo PassportI DOJ Dept_time ContaactNO


D
29823 AP123 82302 21-03- 4 pm 9832434354
2014

34353 AP234 32243 12-04- 5pm 9855645433


2014

Mysql>Insert into Reservation values(‘783-93930’,’21-03-


2014’,04,’Hyderabad’,’8972389289’,’Confirm’);

Insert 5 or more records like-wise

Mysql> Select * from Reservation;

PNRNo DOJ No_of_seats Address ContactNo


837- 21-03- 02 Hyderabad 9837383393
99203 2014
938- 23-03- 04 Hyderbad 9389939202
89894 2014

Mysql> Insert into Cancellation values(‘783-93930’,’21-03-2014’,02,’Confirm’);

Insert 5 or more records like-wise

Mysql> Select * from Cancellation;

PNRNo DOJ No_of_seats Address Status


837-99203 21-03- 02 Hyderabad Confirm
2014
938-89894 23-03- 04 Hyderbad Confirm
2014

Mysql>UPDATE BUS set BusNo=’AP3456’ where BusNo=’AP123’;

28
Mysql> DELETE FROM BUS WHERE BusNo=’AP345’;

Conclusion: The Student is able perform DML Commands like Insert, Update, Delete
and Select

Viva-Voce

1. What are DML commands?


2. Write the syntax for insert command?
3. What is the syntax for update command?

29
4. Write the syntax for delete command?
5. Write the syntax for select command?
6. Difference between DCL and TCL

7.Querying

Aim: Practice the following Queries:

1. Display unique PNR_NO of all passengers


2. Display all the names of male passengers.
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’.
5. Find the names of Passengers whose age is between 30 and 45.
6. Display all the passengers names beginning with ‘A’.
7. Display the sorted list of Passengers names.

Recommended Hardware / Software Requirements:

 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

Prerequisites: Student must know about the RDBMS

1. Display unique PNR_NO of all reservation

Mysql>Select DISTINCT PNR_NO from Reservation;

PNR_No
783-32923
928-38983

30
2. Display all the names of male passengers.

Mysql> SELECT Name FROM Passenger WHERE Sex=’M’;

Name
Smith
John

31
3. Display the ticket numbers and names of all the passengers.

MySQL> SELECT TicketNo,Name from Ticket, Passenger


name ticketno
Sai 1500
Raju 1502
Ramu 1503

4. Find the ticket numbers of the passengers whose name start with ‘r’ and ends with ‘h’.

MySQL> SELECT Name FROM Passenger WHERE name LIKE ‘R%’


AND name LIKE ‘%H’

Name
Rajesh
Ramesh

32
5. Find the names of Passengers whose age is between 30 and 45.

MySQL> SELECT Name FROM PASSENGER WHERE AGE BETWEEN 30 AND 45

Name
neha
Ramu

6. Display all the passengers names beginning with ‘A’.

33
MySQL> SELECT * FROM PASSENGER WHERE NAME LIKE ‘A%’;

Name
Akash
Avinash
Arivind

7. Display the sorted list of Passengers names

MySQL> SELECT NAME FROM PASSENGER ORDER BY NAME;

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?

2. What is the result of Date functions?

3. What is the result of conversion function?

4. What is Concatenation?

5. What is the difference between LTRIM and RTRIM?

8. Querying

Aim: To Practice Queries using Aggregate functions 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.

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

Prerequisites: Student must know about the RDBMS-SQL

1. Write a Query to display the information present in the passenger and cancellation
tables

MySQL> SELECT * FROM RESERVATION

UNION

SELECT * FROM CANCELLATION;

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

2. Display the Minimum age of the Passenger

MySQL> SELECT MIN(AGE) as MINAGE FROM PASSENGER;

MINAGE
23

37
3. Find number of tickets booked for each PNR_No using GROUP BY CLAUSE

MySQL> SELECT PNR_NO,SUM(No_of_SEATS) AS SUM_OF_SEATS FROM


RESERVATION GROUP BY PNR_NO;

PNR_NO SUM_OF_SEATS

78393445 5

78393930 4

4. Find the distinct PNR Numbers that are present.


38
MySQL> SELECT DISTINCT PNR_NO FROM RESERVATION;

PNR_NO

78393445

78393930

5.Mysql> select sum(No_of_seats) from Cancellation;

SUM(NO_OF_SEATS)
----------------
6

39
Viva-Voce:

1. What is the difference between SUM and COUNT ?


2. What will you get when you use MIN ?
3. What will you get when you use MAX ?
4. What is VIEW ? and What will you get when you use VIEW
5. What is difference between DROP table and DELETE?
6. What will you get when you use AVG?

9. Querying

Aim: To Practice Queries using Aggregate functions for following

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.

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

Prerequisites: Student must know about the RDBMS-SQL

40
5. Find the number of tickets booked by a passenger where the number of seats is
greater than 1.

MySQL> select * from reservation where NO_of_seats >1;

6. Find the total number of cancelled seats.

MySQL> SELECT SUM(NO_OF_SEATS) AS CANCELED_SEATS FROM

CANCELLATION;
CANCELLED_SEATS
03

41
Conclusion: The Student is able to execute the Queries using SQL Clauses

10.Triggers

Aim: Creation of insert trigger, delete trigger and update trigger.

Recommended Hardware / Software Requirements:

 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

Prerequisites: Student must know about the Relational Database SQL-Triggers.

MySQL>CREATE TABLE BUS(BUSNO VARCHAR(10) NOT NULL,

SOURCE VARCHAR(10), DESTINATION VARCHAR(10),

CAPACITY INT(2), PRIMARY KEY(BUSNO));

MySQL>INSERT INTO BUS VALUES('AP123','HYD','CHENNAI','40');

42
i) CREATE TABLE BUS_AUDIT1(ID INT NOT NULL AUTO_INCREMENT,
SOURCE

VARCHAR(10) NOT NULL, CHANGEDON DATETIME DEFAULT NULL, ACTION

VARCHAR(10) DEFAULT NULL, PRIMARY KEY(ID));

DELIMITER $$

43
CREATE TRIGGER BEFORE_BUS_UPDATE

BEFORE UPDATE ON BUS

FOR EACH ROW

BEGIN

INSERT INTO BUS_AUDIT1

SET action='update',

source=OLD.source,

changedon=NOW();

END$$

i)UPDATE :

MySQL>UPDATE BUS SET SOURCE='KERALA' WHERE BUSNO='AP123'$$

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:

CREATE TRIGGER BEFORE_BUS_INSERT

BEFORE INSERT ON BUS

FOR EACH ROW

BEGIN

INSERT INTO BUS_AUDIT1

SET action='Insert',

source=NEW.source,

changedon=NOW();

END$$

INSERT INTO BUS VALUES('AP789','VIZAG','HYDERABAD',30)$$

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)

CREATE TRIGGER BEFORE_BUS_DELETE

BEFORE DELETE ON BUS

FOR EACH ROW

BEGIN

DELETE FROM BUS_AUDIT1

SET action='Insert',

source=NEW.source,

changedon=NOW();

END$$

DELETE FROM BUS WHERE SOURCE=’HYDERABAD’$$

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?

2. What is BEFORE Trigger?

3. What is AFTER Trigger?

4. What is the difference between BEFORE and AFTER?

5. What is ROW and Statement Triggers?

6. What is INSTEAD Triggers?

7. What are the types on Triggers?

8. It is possible to create Trigger on Views?

11.Procedures

Aim: Creation of stored Procedures and Execution of Procedures and Modification of


Procedures.

Recommended Hardware / Software Requirements:

 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

Prerequisites: Student must know about the Relational Database SQL-Procedures

Ex1:

CREATE PROCEDURE BUS_PROC1()


47
BEGIN

SELECT * FROM BUS;

END$$

CALL BUS_PROC1()$$

BusNo Source Destination CoachType


AP123 Hyderabad Banglore Volvo
AP234 Mumbai Hyderabad Semi-Sleeper

Ex2:

CREATE PROCEDURE SAMPLE2()

BEGIN

DECLARE X INT(3);

SET X=10;

SELECT X;
48
END$$

CALL SAMPLE2()$$

BusNo Source Destination CoachType


AP123 Hyderabad Banglore Volvo
AP234 Mumbai Hyderabad Semi-Sleeper

Ex3: CREATE PROCEDURE SIMPLE_PROC(OUT PARAM1 INT)

BEGIN

SELECT COUNT(*) INTO PARAM1 FROM BUS;

END$$

CALL SIMPLE_PROC(@a)$$

PARAM1
4

Conclusion: The Student is able to work on Stored Procedures.

49
Viva Voce:

1. What is a stored procedure?


2. When would you use stored procedure or functions ?
3. What are external procedures?
4. What is input parameter?
5. How to use Stored Procedures.

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.

Recommended Hardware / Software Requirements:

 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

Prerequisites: Student must know about the Relational SQL-Cursors

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.

There are some steps we have to follow, given below :

 Declare a cursor

 Open a cursor statement

50
 Fetch the cursor

 Close 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.

Syntax : DECLARE cursor_name CURSOR FOR select_statement;

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.

Syntax : OPEN cursor_name;

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.

Synatx : FETCH cursor_name INTO var_name;

If any row exists, then the above statement fetches the next row and cursor pointer moves ahead
to the next row.

4 . Cursor close statement : By this statement closed the open cursor.

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)

mysql> SELECT * FROM Products;

C_id C_Name Address


12303 IBM Bangalore
83893 Infosys Hyderabad

52
Conclusion: The Student is able to work on Cursors.

Viva Voce:

1. What is a cursor?

2. What are the types of cursor?


3. What is the use of parameterized cursor?
4. What is the use of cursor variable?
5. What is a normal cursor?
6. What are Explicit cursor attributes?

Text Books / Reference Books


1. Introduction to SQl, Rick F.Vander Lans,Pearson Education
2. Oracle PL/SQL, B Rosenzweig and E.Silvestrova, Pearson Education
3. SQL & PL/SQL for Oracle 10g, Black Book, Dr P.S.Deshpande,Dream Tech.
4. Oracle Database 11g PL/SQL Programming,M,Mc.Laughlin,TMH
5. SQL Fundamentals,JJ.Patrick,Pearson Education

53
54

Das könnte Ihnen auch gefallen