ex4
ex4
ex4
Prepared By
Name:
Verified By
Head of the Department:
DEPARTMENT OF INFORMATION TECHNOLOGY
INSTITUTION VISION
To be a premier Institution in Engineering & Technology and Management with competency,
values and social consciousness.
INSTITUTION MISSION
IM1 Provide high quality academic programs, training activities and research facilities.
IM3 Contribute to the Economical and technological development of the region, state and nation.
DEPARTMENT VISION
To be a recognized knowledge center in the field of Information Technology with self -
motivated, employable engineers to society.
DEPARTMENT MISSION
The Department has following Missions:
DM1 To offer high quality student centric education in Information Technology.
PO Description
PO 1 Engineering Knowledge: Apply the knowledge of mathematics, science, engineering fundamentals, and
an engineering specialization to the solution of complex engineering problems.
Problem Analysis: Identify, formulate, review research literature, and analyze complex engineering
PO 2
problems reaching substantiated conclusions using first principles of mathematics, natural sciences, and engineering
sciences.
Design / development of Solutions: Design solutions for complex engineering problems and design system
PO 3 components or processes that meet the specified needs with appropriate consideration for the
public health and safety, and the cultural, societal, and environmental considerations.
Conduct investigations of complex problems: Use research-based knowledge and research methods including
PO 4 design of experiments, analysis and interpretation of data, and synthesis of the information to
provide valid conclusions.
Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern engineering and IT
PO 5
tools including prediction and modeling to complex engineering activities with an understanding
of the limitations.
The engineer and Society: Apply reasoning informed by the contextual knowledge to assess societal, health, safety,
PO 6 legal and cultural issues and the consequent responsibilities relevant to the professional
engineering practice.
Environment and sustainability: Understand the impact of the professional engineering solutions in
PO 7
societal and environmental contexts, and demonstrate the knowledge of, and need for sustainable development.
PO 8 Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms of the
engineering practice
PO 9 Individual and team work: Function effectively as an individual, and as a member or leader in diverse
teams, and in multidisciplinary settings.
Communication: Communicate effectively on complex engineering activities with the engineering
PO 10 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.
Project management and finance: Demonstrate knowledge and understanding of the engineering and
PO 11 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.
PO 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.
Program Specific Outcomes
Software Development: To apply the knowledge of Software Engineering, Data Communication, Web Technology
PSO 1
and Operating Systems for building IOT and Cloud Computing applications.
PSO 2 Industrial Skills Ability: Design, develop and test software systems for world-wide network of computers to
provide solutions to real world problems.
PSO 3 Project implementation: Analyze and recommend the appropriate IT Infrastructure required for the implementation
of a project.
DEPARTMENT OF INFORMATION TECHNOLOGY
C22L2.1 Design database schema for a given application and apply normalization.
C22L2.2 1. Acquires skills in using SQL commands for data definition and data
manipulation.
C22L2.3 Develop solutions for database applications using procedures, cursors and
triggers.
CO PO1 PO2 PO3 PO4 PO5 PO6 PO7 PO8 PO9 PO10 PO11 PO12 PSO1 PSO2 PSO3
C22L2.1 3 3 3 2 - 2 - - 2 - - 2 2 3 -
C22L2..2 3 2 2 - - - - - - - - 2 2 2 -
C22L2.3 3 3 2 2 - - - - - - - 2 2 2 1
insert into Bus values (1234, 'hyderabad', 'tirupathi');insert into Bus values(2345, 'hyderabad', 'banglore');insert into
Experiment 6: Querying (using ANY, ALL, IN, EXISTS, NOTEXIST, UNION, INTERSECT, Constraints etc.
In this week you are going to practice queries (along with sub queries) using ANY, ALL, IN, EXISTS,
NOTEXIST, UNION, INTERSECT, Constraints etc.
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. Findthenamesofpassengerswhoseageisbetween30 and 45.
6. Display all the passengers names beginning with 'A'
7. Display the sorted list of passenger’s names
Experiment 10: Usage of 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. Close the cursor when done
CREATE PROCEDURE myproc(in_customer_idINT) BEGIN
DECLARE v_id INT;
DECLARE v_name VARCHAR(30);
DECLARE c1 CURSOR FOR
SELECT stdid, stdFirstname FROM students WHERE stdid-in_customer_id;
OPENc1;
FETCHc1INTOv_id,v_name; CLOSE c1;
END;
Tables:
BUS
BusNo: VARCAHR : PK (primarykey)
Source: VARCHAR
Destination: VARCHAR
Passenger
PPNO: VARCHAR(15) : PK Name:
VARCHAR(15)
Age: INT(4)
Sex:CHAR(10) : Male/Female
Address: VARCHAR(20)
Passenger_Tickets
PPNO:VARCHAR(15): PK
Ticket_No:NUMERIC(9)
Reservation
PNR_No: NUMERIC(9) : FK
Journey_date: DATETIME(8)
No_of_seats: INT(8) Address:
VARCHRA(50)
Contact_No: NUMERIC(9)-->Should not less than 9 and Should not accept any other character other than
interger
STATUS:CHAR(2): Yes/No
Cancellation
PNR_No: NUMERIC(9):FK
Journey_date: DATETIME(8)
No_of_seats : INT(8) Address:
VARCHRA(50)
Contact_No:NUMERIC(9)-->Should not less than 9 and Should not accept any other character other than interger
STATUS:CHAR(2):Yes/No
Lab Structure
1.DIMENSIONS OF THE LAB
Area of the lab in Sqmts : Sqm
2. CAPACITY OF THE LAB :
3. EQUIPMENTS
Computer Systems (Clients) :
CPU :
Monitors :
Key Board :
Mouse :
4. SYSTEM CONFIGURATION : DELLE1916HV
Speed : 3.10 GHz, 2GB RAM
Hard Disk : 500 GB
HCL LED Monitor Size : 18.5
5. SOFTWARE : Turbo C++, MYSQL, Eclipse, Windows
OS,Open Office
6. AMBIENCE
Printers : 00
Projector : 01
Computer Tables :
Student Chairs :
Charts :
Photo Frames :
Switch/Hub :
White Boards :
A/C s :
Power Backup : UPS
TIME TABLE
12:40
Time 9:40-10:40 10:40-11:40 11:40-12:40
To
1:20-2:15 2:15-3:10 3:10-4:00
1 2 3 1:20 4 5 6
Days
Monday L
Tuesday U
Wednesday N
Thursday C
Friday H
Saturday
GENERAL LABORATORY INSTRUCTIONS
1. Students are advised to come to the laboratory at least 5 minutes before (to the starting
time), thosewho come after 5 minutes will not be allowed into the lab.
2. Plan your task properly much before to the commencement, come prepared to the lab with the
synopsis /program / experiment details.
3. Student should enter into the laboratory with:
a. Laboratory observation notes with all the details (Problem statement, Aim,
Algorithm, Procedure, Program, Expected Output, etc.,) filled in for the lab session.
4. Sign in the laboratory login register, write the TIME-IN, and occupy the computer system
allotted toyou by the faculty.
5. Execute your task in the laboratory, and record the results / output in the lab
observation notebook, and get certified by the concerned faculty.
6. All the students should be polite and cooperative with the laboratory staff, must
maintain thediscipline and decency in the laboratory.
7. Computer labs are established with sophisticated and high end branded systems, which
should beutilized properly.
8. Students / Faculty must keep their mobile phones in SWITCHED OFF mode during the lab
sessions. Misuse of the equipment, misbehaviors with the staff and systems etc., will attract severe
punishment.
9. Students must take the permission of the faculty in case of any urgency to go out ; if anybody
found loitering outside the lab / class without permission during working hours will be treated
seriously and punished appropriately.
10. Students should LOG OFF/ SHUT DOWN the computer system before he/she leaves the lab
after completing the task (experiment) in all aspects. He/she must ensure the system / seat is kept
properly.
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.
E-R Model
Bus
BusNo
Source
Destination
CoachType
SCHEMA
Bus: Bus(BusNo :String ,Source : String, Destination: String, Coach Type: String)
Ticket
TicketNo
DOJ
Address
ContactNo
BusNo
[1]
SeatNo
Source
Destination
SCHEMA
Ticket (TicketNo: string, DOJ: date, Address: string, ContactNo : string, BusNo:String
SeatNo : Integer, Source: String, Destination: String)
Passenger
PassportID
TicketNo
Name
ContactNo
Age
Sex
Address
SCHEMA
Passenger (PassportID: String, TicketNo :string, Name: String, ContactNo: string, Age:
integer, Sex: character, Address: String)
[2]
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)
[3]
Cancellation
PNRNo
DOJ
SeatNo
ContactNo
Status
SCHEMA
Cancellation (PNRNo: String, DOJ: Date, SeatNo: integer, ContactNo: String, Status:
String)
[4]
CONCEPT DESIGN WITH E-R MODEL
[5]
Viva Questions:
1.Define DBMS?
2. Define the terms i) Entity ii) Entity set iii) weak entity set iv) strong entity set?
3.What is ER-diagram?
4.What are the different types of entities?
5. List various types of attributes?
[6]
EXPERIMENT – 2
RELATIONAL MODEL
AIM: To Represent all the entities (Strong, Weak) in tabular fashion. Represent relationships in a tabular fashion.
Mysql>desc Bus;
Ticket:
Ticket(TicketNo: string, DOJ: date, Address:string,ContactNo: string, BusNo:String, SeatNo :Integer, Source: String,
Destination: String)
[7]
ColumnName Datatype Constraints Type of Attributes
TicketNo Varchar(20) Primary Key Single-valued
Mysql> create table ticket(ticketno varchar(20), doj date,address varchar(20),contactno int, busno
varchar(20),seatno int,source varchar(10),destination varchar(10),primary key(ticketno,busno) foreign key(busno)
references bus(busno);
Mysql>desc Ticket;
Passenger:
Type of
ColumnName Datatype Constraints
Attributes
PassportID Varchar(15) Primary Key Single-valued
TicketNo Varchar(20) Foreign Key Single-valued
[8]
Name Varchar(20) Composite
ContactNo Varchar(20) Multi-valued
Age Integer Single-valued
Sex character Simple
Address Varchar(20) Composite
Reservation:
[9]
BusNo Varchar(10) Foreign Single-valued
Key
SeatNo Integer Simple
Mysql> Create table Resevation(PNRNo varchar(20),DOJ date,NoofSeates integer,Address varchar(20),ContactNo
varchar(20),BusNo varchar(20),SeatNo integer, primary key(PNRNo,BusNo),foreign key(BusNo) references
Bus(BusNo));
Cancellation:
[11]
EXPERIMENT – 3
NORMALIZATION
AIM: Apply the database Normalization techniques for designing relational database tables to minimize
duplication of information like 1NF, 2NF, 3NF, BCNF.
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.
P is a super key.
[12]
Normalized tables are:-
Mysql> Create table Reservation2(PNRNO integer Primary key, JourneyDate DateTime,NoofSeats int,Address
varchar(20),ContactNo Integer);
Mysql> Create table Ticket2(TicketNo Integer Primary key,JourneyDate DateTime, Age Int(4),Sex char(2),Source
varchar(20),Destination varchar(20),DeptTime varchar(2));
Viva Questions:
1.Define Redundancy?
2.What is decomposition?
3.What is Normalization?
4.What is fully functional dependency?
5.List the different types of Normal forms?
[13]
EXPERIMENT – 4
PRACTICING DDL COMMANDS
[14]
Mysql>Alter Table passenger3 add Foreign key(TicketNo) references Ticket(TicketNo);
[15]
Mysql>Alter table passenger drop foreign key fk1;
Viva Questions:
1.What is DDL?
5.Define Database?
[16]
EXPERIMENT – 5
PRACTICING DML COMMANDS
AIM: Create a DML Commands are used to manage data within the scheme objects.
DML Commands:
[17]
mysql> select * from Bus2;
[18]
mysql> select * from Passenger2;
[19]
UPDATE COMMAND ON BUS2 RELATION
mysql> Update Bus2 SET Source='Secundrabad' where BusNo=1234; Query OK, 1 row affected (0.05 sec)
[20]
DELETE COMMAND ON BUS2 RELATION
mysql> Delete from Bus2 where BusNo=1234; Query OK, 1 row affected (0.05 sec)
[21]
mysql> Delete from Bus2 where Source=’Secundrabad’; Query OK, 1 row affected (0.05 sec)
Viva Questions:
1.What is DML?
2.What is the use of DML in DBMS?
3.What are the DML Commands?
4.What is the use of Alter command in DBMS?
5.Define view?
[22]
EXPERIMENT – 6
Querying (using ANY, ALL, IN, Exists, NOT EXISTS, UNION, INTERSECT, Constraints etc.)
[23]
mysql> insert into passenger2 values(82302,'Smith',23,'M','Hyderabad');
PNR_No
10201
10202
10203
10204
[25]
2. Display all the names of male passengers.
[26]
[27]
3. Display the ticket numbers and names of all the passengers.
[28]
4. Find the ticket numbers of the passengers whose name start with ‘r’ and ends with ‘h’.
Name
Rajesh
Ramesh
Ramesh
[29]
5. Find the names of Passengers whose age is between 30 and 45.
[30]
6. Display all the passengers names beginning with ‘A’.
Name
Akash
Arivind
Avinash
[31]
7. Display the sorted list of Passengers names
Viva Questions:
[32]
EXPERIMENT – 7
Querying Aggregate Functions (GROUP BY, HAVING and Creation and Dropping of Views)
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
[33]
MySQL> SELECT * FROM RESERVATION UNION
[34]
3. Find number of tickets booked for each PNR_No using GROUP BY CLAUSE
[35]
5 Mysql> select sum(Noofseats) from Cancellation2;
[36]
Creation and Droping of Views
mysql> create table students(sid int primary key,name varchar(15),login varchar(15), age
int,gpa real); mysql> create table Enrolled(sid int,cid int,grade varchar(5),primary
key(sid,cid), foreign key(sid) references students(sid));
E.grade='B';
Viva Questions:
[37]
EXPERIMENT-8
Triggers
[38]
CREATE TRIGGER BEFORE_BUS_UPDATE BEFORE UPDATE ON BUS
UPDATE :
[39]
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
INSERT:
[40]
CREATE TRIGGER BEFORE_BUS_DELETE BEFORE DELETE ON BUS
Examples
BEGIN
END;
[41]
Viva Questions:
1.Define Trigger?
2.What are the types of triggers?
3.What is the advantage of trigger in database
4.Define Active data bases?
5.When we apply trigger?
[42]
Experiment-9
Procedures
Aim: Creation of stored Procedures and Execution of Procedures and Modification of
Procedures.
Ex1:
END$$
CALL BUS_PROC1()$$
Ex2:
CREATE PROCEDURE SAMPLE2() BEGIN
DECLARE X INT(3); SET X=10;
SELECT X;
END$$
Mysql> CALL SAMPLE2()$$
[43]
Ex3: CREATE PROCEDURE SIMPLE_PROC(OUT PARAM1 INT) BEGIN
END$$
[44]
Viva Questions:
[45]
EXPERIMENT-10
USAGE 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.
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.
□ Declare a cursor
[46]
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 thecursor.
If any row exists, then the above statement fetches the next row and cursor
pointer moves ahead to the next row.
Syntax: CLOSE_name;
Delimiter $$
[47]
Viva Questions:
[48]
ADDITIONAL PROGRAMMS
EMPLOYEES TABLE
[49]
DEPARTMENT TABLE
[50]
Sailors , Reserves , Boats Tables
Mysql> Create table Sailors(Sid integer PRIMARY KEY,sname varchar(15), rating int,age
real); Mysql>Create table Reserves(Sid int,Bid int,Day Date);
[51]
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';
[52]
mysql> select S.sname,S.rating+1 AS rating from Sailors S,Reserves R1,Reserves R2 where
S.sid=R1.sid AND S.sid=R2.sid AND R1.day=R2.day AND R1.bid<>R2.bid;
[53]
N , INTERSECT , AND EXCEPT
1).Find the names of sailors who have reserved a red or a green boat.
OR
[54]
2). Find the names of sailors who have reserved both a red and a green boat.
SELECT S.SNAME
SELECT S2.SNAME
NESTED QUERIES
[53]
3) Find the names of Sailors who have NOT reserved a red Boat
1) Find sailors whose rating is better than some sailor called Horatio
[54]
2) Find the sailors with the highest rating.
1) Find the age of the youngest sailor for each rating level.
2) Find the age of the youngest sailor who is eligible to vote for each rating level with at
least two such sailors
[55]
3) For each red boat , find the number of reservations for this boat
4) Find the average age of sailors for each rating level that has at least two sailors
[56]