You are on page 1of 110

Page |1

LAB-PROGRAM NO:1
Roadway Travels:
Roadway travel system has several buses connecting different places in India.
Its main Office is located in one place (i.e. Hyderabad).
The company wants to computerize its operation in the the following areas:
Reservations
Ticketing
Cancellations
AIM: Creation of Entity Sets and identify the Entities, Attributes, Primary Keys for
all the entities and any other keys (i.e Candidate Keys, Foreign Keys etc.)
if any by analyzing above specification carefully.
CREATION OF ENTITY SETS:
Entity Set: An Entity set is a set of entities of same type that share same properties
or attributes.
Attributes: Attributes are descriptive properties processed by each member of an
Entity Set.
Primary Key: A Primary Key is one or more columns in a table, used to uniquely
each record in a table.
Foreign Key: A Foreign key represents relationship between tables. The existence of
a foreign keys implies that the table with the Foreign Key is relates to the Primary
key table, from which the Foreign Key is derived.
CREATION OF BUS ENTITY SET:
BUS (BUS_NO, SOURCE, DESTINATION)
Each BUS is identified by a unique identification bus number that acts as a
Primary Key.
DBMS LAB MANUAL

Page |2

CREATION OF PASSENGER ENTITY SET:


PASSENGER (PNR_NO, NAME, AGE, GENDER, PPNO)
Each passenger is identified by a Unique Identification passenger number that is
considered as a Primary Key.

CREATION OF TICKET ENTITY SET:


TICKET (TICKET _NO, BUS_NO, JOURNEY_DATE, SOURCE,
DESTINATION, DEP_TIME)
Each Ticket issued is identified by Unique Identification ticket number and it is
considered as a Primary Key.

CREATION OF RESERVATION ENTITY SET:


RESERVATION (PNR _NO, TICKET_NO, JOURNEY_DATE,
NO_OF_SEATS, ADDRESS, CONTACT_NO, STATUS)
Each reservation done is identified by unique identification passenger number
which is considered as a Primary Key to the Reservation Relation and also acts as a
Foreign Key Relationship with the Passenger relation.

CREATION OF CANCELLATION ENTITY SET:


CANCELLATION (PNR _NO, TICKET_NO, JOURNEY_DATE,
NO_OF_SEATS, ADDRESS, CONTACT_NO, STATUS)
Each cancellation done is identified by unique identification passenger number
which is considered as a Primary Key to the Relation Cancellation and also acts as a
Foreign Key Relationship with the Passenger relation?

DBMS LAB MANUAL

Page |3

CREATION OF WAITINGLIST ENTITY SET:


WAITINGLIST (PNR _NO, TICKET_NO, JOURNEY_DATE,
NO_OF_SEATS, ADDRESS, CONTACT_NO, STATUS)
Each waitinglist passenger is identified by unique identification passenger
number which is considered as a Primary Key to the Relation waitinglist and also acts
as a Foreign Key Relationship with the Passenger relation.

DBMS LAB MANUAL

Page |4

LAB-PROGRAM NO:2
AIM: Draw the E-R Diagram for the Entity Set BUS, PASSENGER,
TICKET, RESERVATION, CANCELLATION and WAITINGLIST.
Relate the entities appropriately and indicate the type of
Relationships among these entity sets.
E-R Diagram for the Roadway Travel System:
E-R Model: The Entity Relationship data model considers the Real World
consisting of basic objects.
Relationship: A Relationship expresses an associated among several entities, i.e
relationships among two or more Entities.
Relationship Set: A Relationship Set is a set of relationships of same type.
TYPES OF RELATIONSHIPS:

1:1

ONE TO ONE RELATIONSHIP

1:M

ONE TO MANY RELATIONSHIP

M:1(N)

MANY TO ONE RELATIONSHIP

M:M

MANY TO MANY RELATIONSHIP

DBMS LAB MANUAL

Page |5

E-R DIAGRAM FOR BUS ENTITY SET:

SOURCE

BUS

BUS_NO

DESTINATIO
N

E-R DIAGRAM FOR PASSENGER ENTITY SET:

NAME

PASSENGER

PNR_NO

PPNO

AGE

GENDER

DBMS LAB MANUAL

Page |6

E-R DIAGRAM FOR TICKET ENTITY SET:

JOURNEY_DAT
E
BUS_NO
TICKET

TICKET_N
O

SOURCE

DEPT_TIM
E

DESTINATIO
N

E-R DIAGRAM FOR RESERVATION ENTITY SET:

TICKET_N
O

JOURNEY_DAT
E
NO_OF_SEAT
S
RESEVATION

PNR_NO

ADRESS

STATUS

CONTACT_N
O

DBMS LAB MANUAL

Page |7

E-R DIAGRAM FOR CANCELLATION ENTITY SET:

TICKET_N
O

JOURNEY_DAT
E
NO_OF_SEAT
S
CANCELLATION

PNR_NO

ADRESS

STATUS

CONTACT_N
O

E-R DIAGRAM FOR WAITINGLIST ENTITY SET:

TICKET_N
O

JOURNEY_DAT
E
NO_OF_SEAT
S
WAITINGLIST

PNR_NO

ADRESS

STATUS

CONTACT_N
O

DBMS LAB MANUAL

Page |8

RELATIONSHIPS BETWEEN ENTITY SETS:


RELATIONSHIP BETWEEN PASSENGER AND RESERVATION:
NAME

PASSENGER

PNR_NO

AGE

M
PPNO

GENDER

RESERVATIO
N BOOKING

JOURNEY_DAT
E

TICKET_N
O

M
RESEVATION

PNR_NO

NO_OF_SEAT
S

ADRESS

STATUS

CONTACT_N
O

DBMS LAB MANUAL

Page |9

RELATIONSHIP BETWEEN PASSENGER AND BUS:


NAME

PASSENGER

PNR_NO

AGE

M
PPNO

GENDER

TRAVE
L

1
BUS_NO

BUS

SOURCE

DBMS LAB MANUAL

DESTINATIO
N

P a g e | 10

RELATIONSHIP BETWEEN PASSENGER AND CANCELLATION:


NAME

PASSENGER

PNR_NO

AGE

M
PPNO

GENDER

CANCE
L
TICKET

JOURNEY_DAT
E

TICKET_N
O

M
CANCELLATION

PNR_NO

NO_OF_SEAT
S

ADRESS
STATUS

CONTACT_N
O

DBMS LAB MANUAL

P a g e | 11

RELATIONSHIP BETWEEN PASSENGER AND TICKET:


NAME

PASSENGER

PNR_NO

AGE

1
PPNO

GENDER

ISSUE
TICKET
CONFOR
M

BUS_NO

JOURNEY_DAT
E

1
TICKET

TICKET_N
O

DEPT_TIM
E

DESTINATIO
N

DBMS LAB MANUAL

SOURCE

P a g e | 12

RELATIONSHIP BETWEEN PASSENGER AND WAITINGLIST:


NAME

PASSENGER

PNR_NO

AGE

M
PPNO

GENDER

WAITLIS
T
CONFOR
M

JOURNEY_DAT
E

TICKET_N
O

M
WAITINGLIST

PNR_NO

NO_OF_SEAT
S
ADRESS

STATUS

CONTACT_N
O

DBMS LAB MANUAL

P a g e | 13

LAB-PROGRAM NO:3
AIM: Represent all the Entities (i.e BUS, PASSEMGER, TICKET,
RESERVATION, CANCELLATION and WAITINGLIST) in
tabular fashion.
Represent in a Tabular Fashion and represent attributes as
columns in tables based on requirements.

REPRESENTING ENTITIES IN TABULAR FASHION:


TABLE: A table is represented as a 2-Dimentional Structure composed of rows and
columns.
ROW/TUPLE: Each table row/tuple represents a single entity occurrence within the
Entity Set.
COLUMN: Each table column represents an attribute and each column has a distinct
name.
DATA: The intersection of each row and column represents a single data value.
ATTRIBUTE DOMAIN: Each column /attribute has a specified range of values
known as Attribute Domain

DBMS LAB MANUAL

P a g e | 14

TABULAR FORMAT FOR BUS ENTITY SET:


Table Name: BUS
Primary Key: BUS_NO

BUS_NO

SOURCE

DESTINATION

TABULAR FORMAT FOR PASSENGER ENTITY SET:


Table Name: PASSENGER
Primary Key: PNR_NO

PNR_NO

NAME

AGE

GENDER

PPNO

TABULAR FORMAT FOR TICKET ENTITY SET:


Table Name: TICKET
Primary Key: TICKET_NO
Foreign Key: BUS_NO
TICKET_NO

BUS_NO

JOURNEY_DATE SOURCE

DBMS LAB MANUAL

DESTINATION

DEPT_TIME

P a g e | 15

TABULAR FORMAT FOR RESERVATION ENTITY SET:


Table Name: RESERVATION
Primary Key: PNR_NO
Foreign Key: PNR_NO, TICKET_NO
PNR_
NO

TICKET_
NO

JOURNEY _
DATE

NO_OF _
SEATS

ADDRESS CONTACT_NO STATUS

TABULAR FORMAT FOR CANCELLATION ENTITY SET:


Table Name: CANCELLATION
Primary Key: PNR_NO
Foreign Key: PNR_NO, TICKET_NO
PNR_
NO

TICKET_
NO

JOURNEY _
DATE

NO_OF _
SEATS

DBMS LAB MANUAL

ADDRESS CONTACT_NO STATUS

P a g e | 16

TABULAR FORMAT FOR WAITINGLIST ENTITY SET:


Table Name: WAITINGLIST
Primary Key: PNR_NO
Foreign Key: PNR_NO, TICKET_NO
PNR_
NO

TICKET_
NO

JOURNEY _
DATE

NO_OF _
SEATS

DBMS LAB MANUAL

ADDRESS CONTACT_NO STATUS

P a g e | 17

LAB-PROGRAM NO:4
Roadways Travel System - PRACTICING DDL COMMANDS
AIM: Creation, Altering and Dropping of database tables (i.e., BUS, TICKET,
PASSENGER, RESERVATION, CANCELLATION, WAITINGLIST).

CREATION OF DATABASE TABLES


SYNTAX:

CREATE TABLE <TABLENAME>(


VAR_NAME_1 DATATYPE [CONSTRAINT],
VAR_NAME_2 DATATYPE [CONSTRAINT],
PRIMARY KEY( COLOUMN-1 [,COLOUMN-2]),
FOREIGN KEY (COLOUMN-1) REFERENCES
<TABLENAME> );

NOTE: WE CAN HAVE ONLY ONE FOREIGN KEY RELATIONSHIP WITH ONLY
ONE TABLE ONLY. (i.e. here we are using Foreign Key Relationships with 2
different tables in our programs)

CREATION OF BUS TABLE


SQL> CREATE TABLE BUS(BUS_NO VARCHAR2(10) NOT NULL,
2
SOURCE VARCHAR2(10) NOT NULL,
3
DESTINATION VARCHAR2 (10) NOT NULL,
4
PRIMARY KEY (BUS_NO) );
Table created.
SQL> DESC BUS
Name
-----------------------------------BUS_NO
SOURCE
DESTINATION

Null?
--------

Type
----------------------------

NOT NULL VARCHAR2(10)


NOT NULL VARCHAR2(10)
NOT NULL VARCHAR2(10)

DBMS LAB MANUAL

P a g e | 18

CREATION OF TICKET TABLE


NOTE: WE CAN HAVE ONLY ONE FOREIGN KEY RELATIONSHIP WITH ONLY
ONE TABLE ONLY. (i.e. here we are using two Foreign Key Relationships with
BUS TABLE)
SQL> CREATE TABLE TICKET(TICKET_NO NUMBER(10) NOT NULL,
2
BUS_NO VARCHAR2(10),
3
JOURNEY_DATE DATE,
4
SOURCE VARCHAR2(10),
5
DESTINATION VARCHAR2(10),
6
DEP_TIME VARCHAR(8),
7
PRIMARY KEY(TICKET_NO),
8
FOREIGN KEY (BUS_NO) REFERENCES BUS );
Table created.
SQL> DESC TICKET;
Name
----------------------------------TICKET_NO
BUS_NO
JOURNEY_DATE
SOURCE
DESTINATION
DEP_TIME

Null?
-------NOT NULL

Type
---------------------------NUMBER(10)
VARCHAR2(10)
DATE
VARCHAR2(10)
VARCHAR2(10)
VARCHAR2(8)

SQL>

CREATION OF PASSENGER TABLE


SQL>CREATE TABLE PASSENGER(PNR_NO NUMBER(10) NOT NULL,
2
NAME VARCHAR2(15),
3
AGE NUMBER(3),
4
GENDER CHAR(1) DEFAULT 'M',
5
PPNO VARCHAR2(15),
6
PRIMARY KEY (PNR_NO) );
Table created.

DBMS LAB MANUAL

P a g e | 19
SQL> DESC PASSENGER
Name
Null?
-------------------------------- --------

Type
----------------------------

PNR_NO
NAME
AGE
GENDER
PPNO

NUMBER(10)
VARCHAR2(15)
NUMBER(3)
CHAR(1)
VARCHAR2(15)

NOT NULL

CREATION OF RESERVATION TABLE


NOTE: WE CAN HAVE ONLY ONE FOREIGN KEY RELATIONSHIP WITH ONLY
ONE TABLE ONLY. (i.e. here we are using two Foreign Key Relationships with &
PASSENGER & TICKET TABLES)
SQL> CREATE TABLE RESERVATION(PNR_NO NUMBER(10) NOT NULL,
2
TICKET_NO NUMBER(10) DEFAULT 0,
3
JOURNEY_DATE DATE,
4
NO_OF_SEATS NUMBER(2) NOT NULL,
5
ADDRESS VARCHAR2(25) NOT NULL,
6
CONTACT_NO NUMBER(10) NOT NULL,
7
STATUS CHAR(5) DEFAULT 'NO',
8
PRIMARY KEY (PNR_NO),
9
FOREIGN KEY (PNR_NO) REFERENCES PASSENGER,
10
FOREIGN KEY (TICKET_NO) REFERENCES TICKET );
Table created.
SQL> DESC RESERVATION
Name
Null?
--------------------------------- --------

Type
----------------------------

PNR_NO
TICKET_NO
JOURNEY_DATE
NO_OF_SEATS
ADDRESS
CONTACT_NO
STATUS

NUMBER(10)
NUMBER(10)
DATE
NUMBER(2)
VARCHAR2(25)
NUMBER(10)
CHAR(5)

NOT NULL
NOT NULL
NOT NULL
NOT NULL

SQL>
DBMS LAB MANUAL

P a g e | 20

CREATION OF CANCELLATION TABLE


NOTE: WE CAN HAVE ONLY ONE FOREIGN KEY RELATIONSHIP WITH ONLY
ONE TABLE ONLY .(i.e here we are using two Foreign Key Relationships with
RESERVATION & TICKET TABLES)

SQL> CREATE TABLE CANCELLATION(PNR_NO NUMBER(10) NOT NULL,


2
TICKET_NO NUMBER(10) DEFAULT 0,
3
JOURNEY_DATE DATE,
4
NO_OF_SEATS NUMBER(2) NOT NULL,
5
ADDRESS VARCHAR2(25) NOT NULL,
6
CONTACT_NO NUMBER(10) NOT NULL,
7
STATUS CHAR(5) DEFAULT 'NO',
8
PRIMARY KEY (PNR_NO),
9
FOREIGN KEY (PNR_NO) REFERENCES RESERVATION ,
10
FOREIGN KEY (TICKET_NO) REFERENCES TICKET);
Table created.
SQL> DESC CANCELLATION
Name
------------------------PNR_NO
TICKET_NO
JOURNEY_DATE
NO_OF_SEATS
ADDRESS
CONTACT_NO
STATUS

Null?
--------------NOT NULL

Type
--------------------------NUMBER(10)
NUMBER(10)
DATE
NOT NULL NUMBER(2)
NOT NULL
VARCHAR2(25)
NOT NULL NUMBER(10)
CHAR(5)

DBMS LAB MANUAL

P a g e | 21

CREATION OF WAITINGLIST TABLE


NOTE: WE CAN HAVE ONLY ONE FOREIGN KEY RELATIONSHIP WITH ONLY
ONE TABLE ONLY .(i.e here we are using two Foreign Key Relationships with
RESERVATION & TICKET TABLES)
SQL> CREATE TABLE WAITINGLIST(PNR_NO NUMBER(10) NOT NULL,
2
TICKET_NO NUMBER(10) DEFAULT 0,
3
JOURNEY_DATE DATE,
4
NO_OF_SEATS NUMBER(2) NOT NULL,
5
ADDRESS VARCHAR2(25) NOT NULL,
6
CONTACT_NO NUMBER(10) NOT NULL,
7
STATUS CHAR(5) DEFAULT 'NO',
8
PRIMARY KEY (PNR_NO),
9
FOREIGN KEY (PNR_NO) REFERENCES RESERVATION ,
10
FOREIGN KEY (TICKET_NO) REFERENCES TICKET);
Table created.
SQL> DESC WAITINGLIST;
Name
------------------------------PNR_NO
TICKET_NO
JOURNEY_DATE
NO_OF_SEATS
ADDRESS
CONTACT_NO
STATUS

Null?
-----------------NOT NULL
NOT NULL
NOT NULL
NOT NULL

Type
---------------------------NUMBER(10)
NUMBER(10)
DATE
NUMBER(2)
VARCHAR2(25)
NUMBER(10)
CHAR(5)

SQL>

DBMS LAB MANUAL

P a g e | 22

ALTERING DATABASE TABLES


SYNTAX-1:

ALTER TABLE <TABLE NAME>


ADD < NEW_COLUMN_NAME> <NEW_DATATYPE>;

SYNTAX-2:

ALTER TABLE <TABLE NAME>


MODIFY < COLUMN_NAME> <NEW_DATATYPE>;

SYNTAX-3:

ALTER TABLE <TABLE NAME>


DROP COLUMN < COLUMN_NAME> ;

SQL>CREATE TABLE BUS101(BUS_NO VARCHAR2(10) NOT NULL,


SOURCE VARCHAR2(10) NOT NULL,
DESTINATION VARCHAR2(10) NOT NULL,
PRIMARY KEY (BUS_NO));
Table created.
SQL> ALTER TABLE BUS101 MODIFY( BUS_NO NUMBER(10));
Table altered.
SQL> DESC BUS101
Name
------------------------------BUS_NO
SOURCE
DESTINATION

Null?
---------NOT NULL
NOT NULL
NOT NULL

Type
-----------------------------------NUMBER(10)
VARCHAR2(10)
VARCHAR2(10)

SQL>

DBMS LAB MANUAL

P a g e | 23
SQL> ALTER TABLE BUS101 DROP COLUMN DESTINATION;
Table altered.
SQL> SELECT * FROM BUS101;
no rows selected
SQL> DESC BUS101
Name
---------------------------BUS_NO
SOURCE

Null?
------------NOT NULL
NOT NULL

Type
-----------------------------------NUMBER(10)
VARCHAR2(10)

SQL>

DROPPING DATABASE TABLES


SYNTAX: DROP TABLE

<TABLENAME>;

DROPPING BUS TABLE


SQL> DROP TABLE BUS;
Table dropped.
DROPPING CANCELLATION TABLE
SQL> DROP TABLE CANCELLATION;
Table dropped.
DROPPING WAITINGLIST TABLE
SQL> DROP TABLE WAITINGLIST;
Table dropped.

DBMS LAB MANUAL

P a g e | 24
DROPPING RESERVATION TABLE
SQL> DROP TABLE RESERVATION;
Table dropped.
DROPPING PASSENGER TABLE
SQL> DROP TABLE PASSENGER;
Table dropped.
DROPPING TICKET TABLE
SQL> DROP TABLE TICKET;
Table dropped.
SQL>
*******************************************************

DBMS LAB MANUAL

P a g e | 25

LAB-PROGRAM NO:5
Roadways Travel System - PRACTICING DML COMMANDS
AIM: DML operations i.e. Selecting, Inserting, Updating and Deleting rows of database
tables (i.e., BUS, TICKET, PASSENGER, RESERVATION, CANCELLATION,
WAITINGLIST).
SELECT RETRIVE DATA FROM DATABASE
INSERT INSERT DATA INTO A TABLE
UPDATE UPDATES EXISTING DATA WITHIN A TABLE
DELETE DELETES ALL RECORDS FROM ATABLE OR THE
SPECIFIED RECORDS BASED ON WHERE CONDITION
INSERTION OF VALUES INTO DATABASE TABLES
SYNTAX-1:

INSERT INTO <TABLE_NAME>


VALUES (ATTRIBUTE-1, ATTRIBUTE-2, );

SYNTAX-2:

INSERT INTO <TABLE_NAME>


VALUES (&ATTRIBUTE-1, &ATTRIBUTE-2, );

INSERTION OF VALUES INTO BUS TABLE


SQL> INSERT INTO BUS
2 VALUES('AP02-1111','ANANTAPUR','HYDERABAD');
1 row created.
SQL> INSERT INTO BUS
2 VALUES('AP02-2222','ANANTAPUR','BANGALORE');
1 row created.
SQL> INSERT INTO BUS
2 VALUES('AP02-3333','HINDUPUR','TIRUPATI');
1 row created.
SQL> INSERT INTO BUS
2 VALUES('&BUS_NO','&SOURCE','&DESTINATION');
DBMS LAB MANUAL

P a g e | 26
Enter value for bus_no: AP02-4444
Enter value for source: MADANAPALI
Enter value for destination: OOTY
old 2: VALUES('&BUS_NO','&SOURCE','&DESTINATION')
new 2: VALUES('AP02-4444','MADANAPALI','OOTY')
1 row created.
SQL> INSERT INTO BUS
2 VALUES('&BUS_NO','&SOURCE','&DESTINATION');
Enter value for bus_no: AP02-5555
Enter value for source: TIRUPATI
Enter value for destination: BANGALORE
old 2: VALUES('&BUS_NO','&SOURCE','&DESTINATION')
new 2: VALUES('AP02-5555','TIRUPATI','BANGALORE')
1 row created.
SQL> RUN
1 INSERT INTO BUS
2* VALUES('&BUS_NO','&SOURCE','&DESTINATION')
Enter value for bus_no: AP02-6666
Enter value for source: BANGALORE
Enter value for destination: HYDERABAD
old 2: VALUES('&BUS_NO','&SOURCE','&DESTINATION')
new 2: VALUES('AP02-6666','BANGALORE','HYDERABAD')
1 row created.
SQL> /
Enter value for bus_no: AP02-7777
Enter value for source: KADIRI
Enter value for destination: SHIRIDI
old 2: VALUES('&BUS_NO','&SOURCE','&DESTINATION')
new 2: VALUES('AP02-7777','KADIRI','SHIRIDI')
1 row created.
SQL> /
Enter value for bus_no: AP02-8888
Enter value for source: ANATAPUR
Enter value for destination: KANCHI
old 2: VALUES('&BUS_NO','&SOURCE','&DESTINATION')
new 2: VALUES('AP02-8888','ANATAPUR','KANCHI')
1 row created.
DBMS LAB MANUAL

P a g e | 27

SQL> RUN
1 INSERT INTO BUS
2* VALUES('&BUS_NO','&SOURCE','&DESTINATION')
Enter value for bus_no: AP02-9999
Enter value for source: BANGALORE
Enter value for destination: PUTAAPARTY
old 2: VALUES('&BUS_NO','&SOURCE','&DESTINATION')
new 2: VALUES('AP02-9999','BANGALORE','PUTAAPARTY')
1 row created.

DISPALYING TABLE VALUES BY USING SELECT COMMAND


SQL> SELECT * FROM BUS;
BUS_NO
---------AP02-1111
AP02-2222
AP02-3333
AP02-4444
AP02-5555
AP02-6666
AP02-7777
AP02-8888
AP02-9999

SOURCE
---------ANANTAPUR
ANANTAPUR
HINDUPUR
MADANAPALI
TIRUPATI
BANGALORE
KADIRI
ANATAPUR
BANGALORE

DESTINATION
---------HYDERABAD
BANGALORE
TIRUPATI
OOTY
BANGALORE
HYDERABAD
SHIRIDI
KANCHI
PUTAAPARTY

9 rows selected.
SQL>

INSERTION OF VALUES INTO TICKET TABLE


SQL> ALTER TABLE TICKET MODIFY (JOURNEY_DATE VARCHAR2(10) );
Table altered.
SQL> SELECT * FROM TICKET;
no rows selected

DBMS LAB MANUAL

P a g e | 28

SQL> DESC TICKET


Name
---------------------------TICKET_NO
BUS_NO
JOURNEY_DATE
SOURCE
DESTINATION
DEP_TIME

Null?
-----------------NOT NULL

Type
------------------------------NUMBER(10)
VARCHAR2(10)
VARCHAR2(10)
VARCHAR2(10)
VARCHAR2(10)
VARCHAR2(8)

SQL> INSERT INTO TICKET


2
VALUES(&TICKET_NO,'&BUS_NO','&JOURNEY_DATE','&SOURCE','&DESTINATI
ON','&DEPT_TIME');
Enter value for ticket_no: 1101
Enter value for bus_no: AP02-1111
Enter value for journey_date: 25/MAR/11
Enter value for source: ANANTAPUR
Enter value for destination: HYDERABAD
Enter value for dept_time: 10:30 PM
old 2:
VALUES(&TICKET_NO,'&BUS_NO','&JOURNEY_DATE','&SOURCE','&DESTINATI
ON','&DEPT_TIME')
new 2: VALUES(1101,'AP02-1111','25/MAR/11','ANANTAPUR','HYDERABAD','10:30
PM')
1 row created.
SQL> INSERT INTO TICKET
2
VALUES(&TICKET_NO,'&BUS_NO','&JOURNEY_DATE','&SOURCE','&DESTINATI
ON','&DEPT_TIME');
Enter value for ticket_no: 1102
Enter value for bus_no: AP02-2222
Enter value for journey_date: 14/MAY/11
Enter value for source: ANANTAPUR
Enter value for destination: BANGALORE
Enter value for dept_time: 10:45 PM
old 2:
VALUES(&TICKET_NO,'&BUS_NO','&JOURNEY_DATE','&SOURCE','&DESTINATI
ON','&DEPT_TIME')
new 2: VALUES(1102,'AP02-2222','14/MAY/11','ANANTAPUR','BANGALORE','10:45
PM')
1 row created.
DBMS LAB MANUAL

P a g e | 29

SQL> INSERT INTO TICKET


2
VALUES(&TICKET_NO,'&BUS_NO','&JOURNEY_DATE','&SOURCE','&DESTINATI
ON','&DEPT_TIME');
Enter value for ticket_no: 1103
Enter value for bus_no: AP02-3333
Enter value for journey_date: 22/JUN/11
Enter value for source: HINDUPUR
Enter value for destination: TIRUTATI
Enter value for dept_time: 11:30 AM
old 2:
VALUES(&TICKET_NO,'&BUS_NO','&JOURNEY_DATE','&SOURCE','&DESTINATI
ON','&DEPT_TIME')
new 2: VALUES(1103,'AP02-3333','22/JUN/11','HINDUPUR','TIRUTATI','11:30 AM')
1 row created.
SQL> RUN
1 INSERT INTO TICKET
2*
VALUES(&TICKET_NO,'&BUS_NO','&JOURNEY_DATE','&SOURCE','&DESTINATI
ON','&DEPT_TIME')
Enter value for ticket_no: 1104
Enter value for bus_no: AP02-4444
Enter value for journey_date: 12/NOV/11
Enter value for source: MADANAPALI
Enter value for destination: OOTY
Enter value for dept_time: 12:30 PM
old 2:
VALUES(&TICKET_NO,'&BUS_NO','&JOURNEY_DATE','&SOURCE','&DESTINATI
ON','&DEPT_TIME')
new 2: VALUES(1104,'AP02-4444','12/NOV/11','MADANAPALI','OOTY','12:30 PM')
1 row created.
SQL> /
Enter value for ticket_no: 1105
Enter value for bus_no: AP02-5555
Enter value for journey_date: 09/APR/11
Enter value for source: TIRUPATI
Enter value for destination: BANGALORE
Enter value for dept_time: 02:30 PM
old 2:
VALUES(&TICKET_NO,'&BUS_NO','&JOURNEY_DATE','&SOURCE','&DESTINATI
ON','&DEPT_TIME')
new 2: VALUES(1105,'AP02-5555','09/APR/11','TIRUPATI','BANGALORE','02:30 PM')
DBMS LAB MANUAL

P a g e | 30

1 row created.
SQL> RUN
1 INSERT INTO TICKET
2*
VALUES(&TICKET_NO,'&BUS_NO','&JOURNEY_DATE','&SOURCE','&DESTINATI
ON','&DEPT_TIME')
Enter value for ticket_no: 1106
Enter value for bus_no: AP02-6666
Enter value for journey_date: 05/APR/11
Enter value for source: BANGALORE
Enter value for destination: HYDERABAD
Enter value for dept_time: 07:45 AM
old 2:
VALUES(&TICKET_NO,'&BUS_NO','&JOURNEY_DATE','&SOURCE','&DESTINATI
ON','&DEPT_TIME')
new 2: VALUES(1106,'AP02-6666','05/APR/11','BANGALORE ','HYDERABAD','07:45
AM')
1 row created.
SQL> /
Enter value for ticket_no: 1107
Enter value for bus_no: AP02-7777
Enter value for journey_date: 10/APR/11
Enter value for source: KADIRI
Enter value for destination: SHIRIDI
Enter value for dept_time: 05:30 AM
old 2:
VALUES(&TICKET_NO,'&BUS_NO','&JOURNEY_DATE','&SOURCE','&DESTINATI
ON','&DEPT_TIME')
new 2: VALUES(1107,'AP02-7777','10/APR/11','KADIRI','SHIRIDI','05:30 AM')
1 row created.
SQL> /
Enter value for ticket_no: 1108
Enter value for bus_no: AP02-8888
Enter value for journey_date: 20/APR/11
Enter value for source: ANANTAPUR
Enter value for destination: KANCHI
Enter value for dept_time: 01:45 PM
old 2:
VALUES(&TICKET_NO,'&BUS_NO','&JOURNEY_DATE','&SOURCE','&DESTINATI
ON','&DEPT_TIME')
DBMS LAB MANUAL

P a g e | 31
new 2: VALUES(1108,'AP02-8888','20/APR/11','ANANTAPUR','KANCHI','01:45 PM')
1 row created.
SQL> /
Enter value for ticket_no: 1109
Enter value for bus_no: AP02-9999
Enter value for journey_date: 22/APR/11
Enter value for source: BANGALORE
Enter value for destination: PUTAAPARTY
Enter value for dept_time: 09:15 AM
old 2:
VALUES(&TICKET_NO,'&BUS_NO','&JOURNEY_DATE','&SOURCE','&DESTINATI
ON','&DEPT_TIME')
new 2: VALUES(1109,'AP02-9999','22/APR/11','BANGALORE','PUTAAPARTY','09:15
AM')
1 row created.

DISPALYING TABLE VALUES BY USING SELECT COMMAND


SQL> SELECT * FROM TICKET;
TICKET_NO BUS_NO JOURNEY_DA SOURCE DESTINATIO
DEP_TIME
------------------ ----------------------------- ------------------ ---------------------------- ---------1101
AP02-1111 25/MAR/11
ANANTAPUR
HYDERABAD
10:30 PM
1102
AP02-2222 14/MAY/11
ANANTAPUR
BANGALORE
10:45 PM
1103
AP02-3333 22/JUN/11
HINDUPUR
TIRUTATI
11:30 AM
1104
AP02-4444 12/NOV/11
MADANAPALI
OOTY
12:30 PM
1105
AP02-5555 09/APR/11
TIRUPATI
BANGALORE
02:30 PM
1106
AP02-6666 05/APR/11
BANGALORE
HYDERABAD
07:45 AM
1107
AP02-7777 10/APR/11
KADIRI
SHIRIDI
05:30 AM
1108
AP02-8888 20/APR/11
ANANTAPUR
KANCHI
01:45 PM
1109
AP02-9999 22/APR/11
BANGALORE
PUTAAPARTY 09:15 AM
9 rows selected.
SQL> COMMIT;
Commit complete.

DBMS LAB MANUAL

P a g e | 32

NOTE: Integrity Constraint (PRIMARY KEY/FOREIGN KEY) violated as

shown below
SQL> INSERT INTO TICKET
2
VALUES(&TICKET_NO,'&BUS_NO','&JOURNEY_DATE','&SOURCE','&DESTINATI
ON','&DEPT_TIME');
Enter value for ticket_no: 1001
Enter value for bus_no: AP02-1212
Enter value for journey_date: 22/APR/11
Enter value for source: BANGALORE
Enter value for destination: PUTAAPARTY
Enter value for dept_time: 09:15 AM
old 2:
VALUES(&TICKET_NO,'&BUS_NO','&JOURNEY_DATE','&SOURCE','&DESTINATI
ON','&DEPT_TIME')
new 2: VALUES(1001,'AP02-1212','22/APR/11','BANGALORE','PUTAAPARTY','09:15
AM')
INSERT INTO TICKET
*
ERROR at line 1:
ORA-02291: integrity constraint (SYSTEM.SYS_C003937) violated - parent key not
found

INSERTION OF VALUES INTO PASSENGER TABLE


SQL> INSERT INTO PASSENGER
2 VALUES(&PNR_NO,'&NAME',&AGE,'&GENDER','&PPNO');
Enter value for pnr_no: 1221
Enter value for name: CHAITANYA
Enter value for age: 28
Enter value for gender: M
Enter value for ppno: A0502
old 2: VALUES(&PNR_NO,'&NAME',&AGE,'&GENDER','&PPNO')
new 2: VALUES(1221,'CHAITANYA',28,'M','A0502')
1 row created.
SQL> INSERT INTO PASSENGER
2 VALUES(&PNR_NO,'&NAME',&AGE,'&GENDER','&PPNO');
Enter value for pnr_no: 1222
Enter value for name: SHILPA
DBMS LAB MANUAL

P a g e | 33
Enter value for age: 22
Enter value for gender: F
Enter value for ppno: A0503
old 2: VALUES(&PNR_NO,'&NAME',&AGE,'&GENDER','&PPNO')
new 2: VALUES(1222,'SHILPA',22,'F','A0503')
1 row created.
SQL> /
Enter value for pnr_no: 1223
Enter value for name: KRISHNA
Enter value for age: 25
Enter value for gender: M
Enter value for ppno: A0504
old 2: VALUES(&PNR_NO,'&NAME',&AGE,'&GENDER','&PPNO')
new 2: VALUES(1223,'KRISHNA',25,'M','A0504')
1 row created.
SQL> RUN
1 INSERT INTO PASSENGER
2* VALUES(&PNR_NO,'&NAME',&AGE,'&GENDER','&PPNO')
Enter value for pnr_no: 1224
Enter value for name: MOHAN
Enter value for age: 26
Enter value for gender: M
Enter value for ppno: A0505
old 2: VALUES(&PNR_NO,'&NAME',&AGE,'&GENDER','&PPNO')
new 2: VALUES(1224,'MOHAN',26,'M','A0505')
1 row created.
SQL> /
Enter value for pnr_no: 1225
Enter value for name: SAIDEEPTHI
Enter value for age: 24
Enter value for gender: F
Enter value for ppno: A0506
old 2: VALUES(&PNR_NO,'&NAME',&AGE,'&GENDER','&PPNO')
new 2: VALUES(1225,'SAIDEEPTHI',24,'F','A0506')
1 row created.
SQL> INSERT INTO PASSENGER
2 VALUES(&PNR_NO,'&NAME',&AGE,'&GENDER','&PPNO');
Enter value for pnr_no: 1226
DBMS LAB MANUAL

P a g e | 34
Enter value for name: KIRAN
Enter value for age: 27
Enter value for gender: M
Enter value for ppno: A0507
old 2: VALUES(&PNR_NO,'&NAME',&AGE,'&GENDER','&PPNO')
new 2: VALUES(1226,'KIRAN',27,'M','A0507')
1 row created.
SQL> /
Enter value for pnr_no: 1227
Enter value for name: HONEY
Enter value for age: 22
Enter value for gender: F
Enter value for ppno: A0508
old 2: VALUES(&PNR_NO,'&NAME',&AGE,'&GENDER','&PPNO')
new 2: VALUES(1227,'HONEY',22,'F','A0508')
1 row created.
SQL> /
Enter value for pnr_no: 1228
Enter value for name: ARUN
Enter value for age: 25
Enter value for gender: M
Enter value for ppno: A0509
old 2: VALUES(&PNR_NO,'&NAME',&AGE,'&GENDER','&PPNO')
new 2: VALUES(1228,'ARUN',25,'M','A0509')
1 row created.
SQL> /
Enter value for pnr_no: 1229
Enter value for name: MAMATHA
Enter value for age: 23
Enter value for gender: F
Enter value for ppno: A0510
old 2: VALUES(&PNR_NO,'&NAME',&AGE,'&GENDER','&PPNO')
new 2: VALUES(1229,'MAMATHA',23,'F','A0510')
1 row created.
SQL> COMMIT;
Commit complete.

DBMS LAB MANUAL

P a g e | 35

DISPALYING TABLE VALUES BY USING SELECT COMMAND


SQL> SELECT * FROM PASSENGER;
PNR_NO NAME
-----------------------1221 CHAITANYA
1222 SHILPA
1223 KRISHNA
1224 MOHAN
1225 SAIDEEPTHI
1226 KIRAN
1227 HONEY
1228 ARUN
1229 MAMATHA

AGE
--------28
22
25
26
24
27
22
25
23

G
-M
F
M
M
F
M
F
M
F

PPNO
--------------A0502
A0503
A0504
A0505
A0506
A0507
A0508
A0509
A0510

9 rows selected.
SQL>

INSERTION OF VALUES INTO RESERVATION TABLE


SQL> ALTER TABLE RESERVATION MODIFY(JOURNEY_DATE VARCHAR2(10));
Table altered.
SQL> DESC RESERVATION
Name
Null?
----------------------------------------- -------PNR_NO
TICKET_NO
JOURNEY_DATE
NO_OF_SEATS
ADDRESS
CONTACT_NO
STATUS

Type
----------------------------

NOT NULL
NOT NULL
NOT NULL
NOT NULL

SQL> COMMIT;
Commit complete.
SQL>

DBMS LAB MANUAL

NUMBER(10)
NUMBER(10)
VARCHAR2(10)
NUMBER(2)
VARCHAR2(25)
NUMBER(10)
CHAR(5)

P a g e | 36
SQL> INSERT INTO RESERVATION
2
VALUES(&PNR_NO,&TICKET_NO,'&JOURNEY_DATE','&NO_OF_SEATS','&
ADDRESS',&CONTACT_NO,'&STATUS');
Enter value for pnr_no: 1221
Enter value for ticket_no: 1101
Enter value for journey_date: 25/MAR/11
Enter value for no_of_seats: 4
Enter value for address: HNO:1-A-501,ATP
Enter value for contact_no: 9988776655
Enter value for status: YES
old 2:
VALUES(&PNR_NO,&TICKET_NO,'&JOURNEY_DATE','&NO_OF_SEATS','&
ADDRESS',&CONTACT_NO,'&STATUS')
new 2: VALUES(1221,1101,'25/MAR/11','4','HNO:1-A-501,ATP',9988776655,'YES')
1 row created.
SQL> INSERT INTO RESERVATION
2
VALUES(&PNR_NO,&TICKET_NO,'&JOURNEY_DATE','&NO_OF_SEATS','&
ADDRESS',&CONTACT_NO,'&STATUS');
Enter value for pnr_no: 1222
Enter value for ticket_no: 1102
Enter value for journey_date: 14/MAY/11
Enter value for no_of_seats: 2
Enter value for address: HNO:1-A-502,ATP
Enter value for contact_no: 8877665544
Enter value for status: YES
old 2:
VALUES(&PNR_NO,&TICKET_NO,'&JOURNEY_DATE','&NO_OF_SEATS','&
ADDRESS',&CONTACT_NO,'&STATUS')
new 2: VALUES(1222,1102,'14/MAY/11','2','HNO:1-A-502,ATP',8877665544,'YES')
1 row created.
SQL> INSERT INTO RESERVATION
2
VALUES(&PNR_NO,&TICKET_NO,'&JOURNEY_DATE','&NO_OF_SEATS','&
ADDRESS',&CONTACT_NO,'&STATUS');
Enter value for pnr_no: 1223
Enter value for ticket_no: 1103
Enter value for journey_date: 22/JUN/11
Enter value for no_of_seats: 6
Enter value for address: HNO:1-B-504,HDP
DBMS LAB MANUAL

P a g e | 37
Enter value for contact_no: 7766554433
Enter value for status: YES
old 2:
VALUES(&PNR_NO,&TICKET_NO,'&JOURNEY_DATE','&NO_OF_SEATS','&
ADDRESS',&CONTACT_NO,'&STATUS')
new 2: VALUES(1223,1103,'22/JUN/11','6','HNO:1-B-504,HDP',7766554433,'YES')
1 row created.
SQL> RUN
1 INSERT INTO RESERVATION
2*
VALUES(&PNR_NO,&TICKET_NO,'&JOURNEY_DATE','&NO_OF_SEATS','&
ADDRESS',&CONTACT_NO,'&STATUS')
Enter value for pnr_no: 1224
Enter value for ticket_no: 1104
Enter value for journey_date: 12/NOV/11
Enter value for no_of_seats: 3
Enter value for address: HNO:1-C-505,MPL
Enter value for contact_no: 8855223311
Enter value for status:
old 2:
VALUES(&PNR_NO,&TICKET_NO,'&JOURNEY_DATE','&NO_OF_SEATS','&
ADDRESS',&CONTACT_NO,'&STATUS')
new 2: VALUES(1224,1104,'12/NOV/11','3','HNO:1-C-505,MPL',8855223311,'')
1 row created.
SQL> INSERT INTO RESERVATION
2
VALUES(&PNR_NO,&TICKET_NO,'&JOURNEY_DATE','&NO_OF_SEATS','&
ADDRESS',&CONTACT_NO,'&STATUS');
Enter value for pnr_no: 1225
Enter value for ticket_no: 1105
Enter value for journey_date: 09/APR/11
Enter value for no_of_seats: 4
Enter value for address: HNO:2-1-222,TPT
Enter value for contact_no: 9955116677
Enter value for status: NO
old 2:
VALUES(&PNR_NO,&TICKET_NO,'&JOURNEY_DATE','&NO_OF_SEATS','&
ADDRESS',&CONTACT_NO,'&STATUS')
new 2: VALUES(1225,1105,'09/APR/11','4','HNO:2-1-222,TPT',9955116677,'NO')
1 row created.

DBMS LAB MANUAL

P a g e | 38
SQL> RUN
1 INSERT INTO RESERVATION
2*
VALUES(&PNR_NO,&TICKET_NO,'&JOURNEY_DATE','&NO_OF_SEATS','&
ADDRESS',&CONTACT_NO,'&STATUS')
Enter value for pnr_no: 1226
Enter value for ticket_no: 1106
Enter value for journey_date: 05/APR/11
Enter value for no_of_seats: 1
Enter value for address: HNO:3-2-512,ATP
Enter value for contact_no: 3355778899
Enter value for status: YES
old 2:
VALUES(&PNR_NO,&TICKET_NO,'&JOURNEY_DATE','&NO_OF_SEATS','&
ADDRESS',&CONTACT_NO,'&STATUS')
new 2: VALUES(1226,1106,'05/APR/11','1','HNO:3-2-512,ATP',3355778899,'YES')
1 row created.
SQL> INSERT INTO RESERVATION
2
VALUES(&PNR_NO,&TICKET_NO,'&JOURNEY_DATE','&NO_OF_SEATS','&
ADDRESS',&CONTACT_NO,'&STATUS');
Enter value for pnr_no: 1227
Enter value for ticket_no: 1107
Enter value for journey_date: 10/APR/11
Enter value for no_of_seats: 6
Enter value for address: HNO:4-3-666,KDR
Enter value for contact_no: 9876543211
Enter value for status: YES
old 2:
VALUES(&PNR_NO,&TICKET_NO,'&JOURNEY_DATE','&NO_OF_SEATS','&
ADDRESS',&CONTACT_NO,'&STATUS')
new 2: VALUES(1227,1107,'10/APR/11','6','HNO:4-3-666,KDR',9876543211,'YES')
1 row created.
SQL> RUN
1 INSERT INTO RESERVATION
2*
VALUES(&PNR_NO,&TICKET_NO,'&JOURNEY_DATE','&NO_OF_SEATS','&
ADDRESS',&CONTACT_NO,'&STATUS')
Enter value for pnr_no: 1228
Enter value for ticket_no: 1108
Enter value for journey_date: 20/APR/11
Enter value for no_of_seats: 4
DBMS LAB MANUAL

P a g e | 39
Enter value for address: HNO:4-3-777,TPT
Enter value for contact_no: 8822334466
Enter value for status: NO
old 2:
VALUES(&PNR_NO,&TICKET_NO,'&JOURNEY_DATE','&NO_OF_SEATS','&
ADDRESS',&CONTACT_NO,'&STATUS')
new 2: VALUES(1228,1108,'20/APR/11','4','HNO:4-3-777,TPT',8822334466,'NO')
1 row created.
SQL> /
Enter value for pnr_no: 1229
Enter value for ticket_no: 1109
Enter value for journey_date: 22/APR/11
Enter value for no_of_seats: 10
Enter value for address: HNO:5-7-444,MPL
Enter value for contact_no: 9911224433
Enter value for status: YES
old 2:
VALUES(&PNR_NO,&TICKET_NO,'&JOURNEY_DATE','&NO_OF_SEATS','&
ADDRESS',&CONTACT_NO,'&STATUS')
new 2: VALUES(1229,1109,'22/APR/11','10','HNO:5-7-444,MPL',9911224433,'YES')
1 row created.

DBMS LAB MANUAL

P a g e | 40

DISPALYING TABLE VALUES BY USING SELECT COMMAND


SQL> SELECT * FROM RESERVATION;
PNR_NO TICKET_NO JOURNEY_DA NO_OF_SEATS ADDRESS
---------------------------- ---------- ---------- ---------- ---------- ----------- ------------------------CONTACT_NO STATUS
------------------------- -------------------1221
9988776655

1101
YES

25/MAR/11

HNO:1-A-501,ATP

1222
8877665544

1102
YES

14/MAY/11

HNO:1-A-502,ATP

1223
7766554433

1103
YES

22/JUN/11

HNO:1-B-504,HDP

1224
8855223311

1104
NO

12/NOV/11

HNO:1-C-505,MPL

1225
9955116677

1105
NO

09/APR/11

HNO:2-1-222,TPT

1226
3355778899

1106
YES

05/APR/11

HNO:3-2-512,ATP

1227
9876543211

1107
YES

10/APR/11

HNO:4-3-666,KDR

1228
8822334466

1108
NO

20/APR/11

HNO:4-3-777,TPT

1229
9911224433

1109
YES

22/APR/11

10

HNO:5-7-444,MPL

9 rows selected.
SQL> COMMIT;
Commit complete.
DBMS LAB MANUAL

P a g e | 41

INSERTION OF VALUES INTO CANCELLATION TABLE


SQL> ALTER TABLE CANCELLATION MODIFY(JOURNEY_DATE
VARCHAR2(10));
Table altered.
SQL> DESC CANCELLATION
Name
Null?
----------------------------------- -------PNR_NO
NOT NULL
TICKET_NO
JOURNEY_DATE
NO_OF_SEATS
NOT NULL
ADDRESS
NOT NULL
CONTACT_NO
NOT NULL
STATUS

Type
---------------------------NUMBER(10)
NUMBER(10)
VARCHAR2(10)
NUMBER(2)
VARCHAR2(25)
NUMBER(10)
CHAR(5)

SQL>
SQL> INSERT INTO CANCELLATION
2
VALUES(&PNR_NO,&TICKET_NO,'&JOURNEY_DATE','&NO_OF_SEATS','&
ADDRESS',&CONTACT_NO,'&STATUS');
Enter value for pnr_no: 1221
Enter value for ticket_no: 1101
Enter value for journey_date: 25/MAR/11
Enter value for no_of_seats: 4
Enter value for address: HNO:1-A-501,ATP
Enter value for contact_no: 9988776655
Enter value for status: YES
old 2:
VALUES(&PNR_NO,&TICKET_NO,'&JOURNEY_DATE','&NO_OF_SEATS','&
ADDRESS',&CONTACT_NO,'&STATUS')
new 2: VALUES(1221,1101,'25/MAR/11','4','HNO:1-A-501,ATP',9988776655,'YES')
1 row created.
SQL> INSERT INTO CANCELLATION
2
VALUES(&PNR_NO,&TICKET_NO,'&JOURNEY_DATE','&NO_OF_SEATS','&
ADDRESS',&CONTACT_NO,'&STATUS');
Enter value for pnr_no: 1226
Enter value for ticket_no: 1106
Enter value for journey_date: 05/APR/11
DBMS LAB MANUAL

P a g e | 42
Enter value for no_of_seats: 1
Enter value for address: HNO:3-3-512,ATP
Enter value for contact_no: 3355778899
Enter value for status: YES
old 2:
VALUES(&PNR_NO,&TICKET_NO,'&JOURNEY_DATE','&NO_OF_SEATS','&
ADDRESS',&CONTACT_NO,'&STATUS')
new 2: VALUES(1226,1106,'05/APR/11','1','HNO:3-3-512,ATP',3355778899,'YES')
1 row created.
SQL>

DISPALYING TABLE VALUES BY USING SELECT COMMAND


SQL> SELECT * FROM CANCELLATION;
PNR_NO
TICKET_NO JOURNEY_DA NO_OF_SEATS
ADDRESS
---------- ---------- -------------------------------------------------- ----------- ------------------------CONTACT_NO STATUS
---------- ------------ -------1221
9988776655

1101
YES

25/MAR/11

HNO:1-A-501,ATP

1226
3355778899

1106
YES

05/APR/11

HNO:3-3-512,ATP

INSERTION OF VALUES INTO WAITINGLIST TABLE

SQL> ALTER TABLE WAITINGLIST MODIFY(JOURNEY_DATE VARCHAR2(10));


Table altered.

DBMS LAB MANUAL

P a g e | 43
SQL> DESC WAITINGLIST
Name
Null?
---------------------------------- ------PNR_NO
NOT NULL
TICKET_NO
JOURNEY_DATE
NO_OF_SEATS
NOT NULL
ADDRESS
NOT NULL
CONTACT_NO
NOT NULL
STATUS

Type
-----------------------------------NUMBER(10)
NUMBER(10)
VARCHAR2(10)
NUMBER(2)
VARCHAR2(25)
NUMBER(10)
CHAR(5)

SQL> INSERT INTO WAITINGLIST


2
VALUES(&PNR_NO,&TICKET_NO,'&JOURNEY_DATE','&NO_OF_SEATS','&
ADDRESS',&CONTACT_NO,'&STATUS');
Enter value for pnr_no: 1224
Enter value for ticket_no: 1104
Enter value for journey_date: 12/NOV/11
Enter value for no_of_seats: 3
Enter value for address: HNO:1-C-505,MPL
Enter value for contact_no: 8855223311
Enter value for status: YES
old 2:
VALUES(&PNR_NO,&TICKET_NO,'&JOURNEY_DATE','&NO_OF_SEATS','&
ADDRESS',&CONTACT_NO,'&STATUS')
new 2: VALUES(1224,1104,'12/NOV/11','3','HNO:1-C-505,MPL',8855223311,'YES')
1 row created.
SQL> /
Enter value for pnr_no: 1225
Enter value for ticket_no: 1105
Enter value for journey_date: 09/APR/11
Enter value for no_of_seats: 4
Enter value for address: HNO:2-1-222,TPT
Enter value for contact_no: 9955116677
Enter value for status: YES
old 2:
VALUES(&PNR_NO,&TICKET_NO,'&JOURNEY_DATE','&NO_OF_SEATS','&
ADDRESS',&CONTACT_NO,'&STATUS')
new 2: VALUES(1225,1105,'09/APR/11','4','HNO:2-1-222,TPT',9955116677,'YES')
1 row created.

DBMS LAB MANUAL

P a g e | 44
SQL> /
Enter value for pnr_no: 1228
Enter value for ticket_no: 1108
Enter value for journey_date: 20/APR/11
Enter value for no_of_seats: 4
Enter value for address: HNO:4-3-777,TPT
Enter value for contact_no: 8822334466
Enter value for status: YES
old 2:
VALUES(&PNR_NO,&TICKET_NO,'&JOURNEY_DATE','&NO_OF_SEATS','&
ADDRESS',&CONTACT_NO,'&STATUS')
new 2: VALUES(1228,1108,'20/APR/11','4','HNO:4-3-777,TPT',8822334466,'YES')
1 row created.

DISPALYING TABLE VALUES BY USING SELECT COMMAND

SQL> SELECT * FROM WAITINGLIST;


PNR_NO TICKET_NO JOURNEY_DA NO_OF_SEATS ADDRESS
-------------------------------------------------------------------------------------------------------------CONTACT_NO STATU
------------------------------------1224
1104
12/NOV/11
3
HNO:1-C-505,MPL
8855223311 YES
1225
1105
9955116677 YES

09/APR/11

HNO:2-1-222,TPT

1228
1108
8822334466 YES

20/APR/11

HNO:4-3-777,TPT

SQL>

DBMS LAB MANUAL

P a g e | 45

UPDATING TABLE VALUES BY USING UPDATE COMMAND


SYNTAX: UPDATE <TABLENAME>
SET COLUMN_NAME=EXPRESSION
[, COLUMN_NAME=EXPRESSION]
[ WHERE CONDITIONLIST ];
NOTE:
WHERE CLAUSE IN THE UPDATE COMMAND SELECTS THE TUPLES/ROWS
TO BE MODIFIED FROM A SINGLE RELATION/TABLE.
SQL> SELECT * FROM BUS;
BUS_NO
SOURCE
DESTINATIO
---------- ------------------------------------------------------------ ---------AP02-1111
ANANTAPUR
HYDERABAD
AP02-2222
ANANTAPUR
BANGALORE
AP02-3333
HINDUPUR
TIRUPATI
AP02-4444
MADANAPALI
OOTY
AP02-5555
TIRUPATI
BANGALORE
AP02-6666
BANGALORE
HYDERABAD
AP02-7777
KADIRI
SHIRIDI
AP02-8888
ANATAPUR
KANCHI
AP02-9999
BANGALORE
PUTAAPARTY
AP0Z-1212
BANGALORE
HAMPI
AP0Z-1313
ANANTAPUR
MYSORE
BUS_NO
SOURCE
DESTINATIO
---------- ------------------------------------------------------------ ---------AP0Z-1414
KADIRI
MADURAI
12 rows selected.
SQL>
SQL> UPDATE BUS
2 SET SOURCE='TIRUPAHI'
3 WHERE BUS_NO='AP0Z-1313';
1 row updated.

DBMS LAB MANUAL

P a g e | 46
SQL> UPDATE BUS
2 SET SOURCE='HYDERABD', DESTINATION='BHAVANI'
3 WHERE BUS_NO='AP0Z-1212';
1 row updated.
SQL> SELECT * FROM BUS;
BUS_NO
SOURCE
DESTINATIO
---------- -----------------------------------------------------------AP02-1111
ANANTAPUR
HYDERABAD
AP02-2222
ANANTAPUR
BANGALORE
AP02-3333
HINDUPUR
TIRUPATI
AP02-4444
MADANAPALI
OOTY
AP02-5555
TIRUPATI
BANGALORE
AP02-6666
BANGALORE
HYDERABAD
AP02-7777
KADIRI
SHIRIDI
AP02-8888
ANATAPUR
KANCHI
AP02-9999
BANGALORE
PUTAAPARTY
AP0Z-1212
HYDERABD
BHAVANI
AP0Z-1313
TIRUPAHI
MYSORE
BUS_NO
SOURCE
DESTINATIO
---------- -----------------------------------------------------------AP0Z-1414
KADIRI
MADURAI
12 rows selected.
SQL>

DELETING TABLE VALUES BY USING DELETE COMMAND


SYNTAX: DELETE FROM <TABLENAME>
[WHERE CONDITIONLIST];
NOTE:
WHERE CLAUSE IF ALL RECORDS ( TUPLES/ROWS) TO BE DELETED FROM
SPECIFIED RELATION/TABLE, THEN, NO NEED TO USE
THE WHERE CLAUSE.

SQL> DELETE FROM BUS


DBMS LAB MANUAL

P a g e | 47
2 WHERE BUS_NO='AP0Z-1212';
1 row deleted.
SQL> DELETE FROM BUS
2 WHERE BUS_NO='AP0Z-1313';
1 row deleted.
SQL> SELECT * FROM BUS;
BUS_NO
SOURCE
DESTINATIO
---------- -----------------------------------------------------------AP02-1111
ANANTAPUR
HYDERABAD
AP02-2222
ANANTAPUR
BANGALORE
AP02-3333
HINDUPUR
TIRUPATI
AP02-4444
MADANAPALI
OOTY
AP02-5555
TIRUPATI
BANGALORE
AP02-6666
BANGALORE
HYDERABAD
AP02-7777
KADIRI
SHIRIDI
AP02-8888
ANATAPUR
KANCHI
AP02-9999
BANGALORE
PUTAAPARTY
AP0Z-1414
KADIRI
MADURAI
10 rows selected.

SQL> DELETE FROM CANCELLATION;


NOTE: ALL RECORDS (TUPLES/ROWS) WILL BE DELETED FROM SPECIFIED
RELATION/TABLE i.e. CANCELLATION.

****************************************************

LAB-PROGRAM NO:6
Roadways Travel System - Queries along with Sub Queries

DBMS LAB MANUAL

P a g e | 48

AIM: Queries along with Sub Queries on database tables (i.e., BUS, TICKET,
PASSENGER, RESERVATION, CANCELLATION, And WAITINGLIST) using
BETWEEN, ANY, ALL, IN, Exists, NOT EXISTS, UNION, INTERSECT,
Constraints etc...

SPECIAL OPERATORS IN SQL:


IN

Used to check whether an attribute value matches any


value within a value set.

BETWEEN Used to check whether an attribute value is within specified


Range (i.e. between Highest & Lowest value).
LIKE

used to check whether an attribute value matches a given


String Pattern.

EXISTS

Used to check whether a Sub Query returns any rows.

ANY, ALL Compares a value to each value in a list.

SET OPERATION IN SQL:


UNION

The UNION operation combines two Relations and


atomically eliminates Duplicate values.

INTERSECT The INTERSECT operation finds the common Tuples of


two Relations and eliminates Duplicate Tuples.
MINUS/EXCEPT This operation combines Tuples / Rows from 2
relations and returns only the Rows that appear in
the First Relation set & NOT IN Second Relation
Set and atomically eliminates Duplicate values.

Queries along with Sub Queries


SQL> SELECT * FROM BUS;
DBMS LAB MANUAL

P a g e | 49

BUS_NO SOURCE
DESTINATIO
---------------------------------------------------------------------AP02-1111 ANANTAPUR
HYDERABAD
AP02-2222 ANANTAPUR
BANGALORE
AP02-3333 HINDUPUR
TIRUPATI
AP02-4444 MADANAPALI OOTY
AP02-5555 TIRUPATI
BANGALORE
AP02-6666 BANGALORE
HYDERABAD
AP02-7777 KADIRI
SHIRIDI
AP02-8888 ANATAPUR
KANCHI
AP02-9999 BANGALORE
PUTAAPARTY
AP0Z-1414 KADIRI
MADURAI
10 rows selected.
SQL> ALTER TABLE BUS
2 ADD BUS_TYPE VARCHAR2(10);
Table altered.
SQL> DESC BUS
Name
Null?
Type
----------------------------------------- ------------------------------------------------------BUS_NO
SOURCE
DESTINATION
BUS_TYPE

NOT NULL
NOT NULL
NOT NULL

SQL> UPDATE BUS


2 SET BUS_TYPE='AC'
3 WHERE BUS_NO='AP02-1111';
1 row updated.
SQL> /
1 row updated.
SQL> UPDATE BUS
2 SET BUS_TYPE='NON_AC'
3 WHERE BUS_NO='AP02-2222';

DBMS LAB MANUAL

VARCHAR2(10)
VARCHAR2(10)
VARCHAR2(10)
VARCHAR2(10)

P a g e | 50
1 row updated.
SQL> UPDATE BUS
2 SET BUS_TYPE='AC'
3 WHERE BUS_NO='AP02-3333';
1 row updated.
SQL> UPDATE BUS
2 SET BUS_TYPE='AC'
3 WHERE BUS_NO='AP02-4444';
1 row updated.
SQL> UPDATE BUS
2 SET BUS_TYPE='NON_AC'
3 WHERE BUS_NO='AP02-5555';
1 row updated.
SQL> UPDATE BUS
2 SET BUS_TYPE='AC'
3 WHERE BUS_NO='AP02-6666';
1 row updated.
SQL> UPDATE BUS
2 SET BUS_TYPE='AC'
3 WHERE BUS_NO='AP02-7777';
1 row updated.
SQL> UPDATE BUS
2 SET BUS_TYPE='NON_AC'
3 WHERE BUS_NO='AP02-8888';
1 row updated.
SQL> UPDATE BUS
2 SET BUS_TYPE='NON_AC'
3 WHERE BUS_NO='AP02-9999';
1 row updated.
SQL> UPDATE BUS
2 SET BUS_TYPE='NON_AC'
DBMS LAB MANUAL

P a g e | 51
3 WHERE BUS_NO='AP0Z-1414';
1 row updated.
SQL> SELECT * FROM BUS;
BUS_NO
SOURCE
DESTINATIO
BUS_TYPE
-------------------------------------------------------------------------------------------------------AP02-1111
ANANTAPUR
HYDERABAD
AC
AP02-2222
ANANTAPUR
BANGALORE
NON_AC
AP02-3333
HINDUPUR
TIRUPATI
AC
AP02-4444
MADANAPALI
OOTY
AC
AP02-5555
TIRUPATI
BANGALORE
NON_AC
AP02-6666
BANGALORE
HYDERABAD
AC
AP02-7777
KADIRI
SHIRIDI
AC
AP02-8888
ANATAPUR
KANCHI
NON_AC
AP02-9999
BANGALORE
PUTAAPARTY
NON_AC
AP0Z-1414
KADIRI
MADURAI
NON_AC
10 rows selected.
SQL> COMMIT;
Commit complete.
SQL>

QUERY-1: Display the details of passengers who are traveling in AC


(Using only IN Operator).
SQL> SELECT * FROM RESERVATION
2 WHERE TICKET_NO IN ( SELECT TICKET_NO FROM TICKET
3
WHERE BUS_NO IN ( SELECT BUS_NO FROM BUS
4
WHERE BUS_TYPE='AC'));

PNR_NO TICKET_NO JOURNEY_DA NO_OF_SEATS ADDRESS


----------------------------------------------------------------------------------------------------------------CONTACT_NO STATUS
------------------------------------DBMS LAB MANUAL

P a g e | 52
1221
9988776655

1101
YES

25/MAR/11

HNO:1-A-501,ATP

1223
7766554433

1103
YES

22/JUN/11

HNO:1-B-504,HDP

1224
8855223311

1104

12/NOV/11

HNO:1-C-505,MPL

1226
3355778899

1106
YES

05/APR/11

HNO:3-2-512,ATP

1227
1107
9876543211 YES

10/APR/11

HNO:4-3-666,KDR

SQL>

QUERY-2: Display the details of passengers who are traveling IN NON_AC


(Using only IN Operator).
SQL> SELECT * FROM RESERVATION
2 WHERE TICKET_NO IN ( SELECT TICKET_NO FROM TICKET
3
WHERE BUS_NO IN ( SELECT BUS_NO FROM BUS
4
WHERE BUS_TYPE='NON_AC'));
PNR_NO TICKET_NO JOURNEY_DA NO_OF_SEATS ADDRESS
----------------------------------------------------------------------------------------------------------------CONTACT_NO STATUS
------------------------------------1222
1102
14/MAY/11
2
HNO:1-A-502,ATP
8877665544
YES
1225
9955116677

1105
NO

09/APR/11

HNO:2-1-222,TPT

1228
8822334466

1108
NO

20/APR/11

HNO:4-3-777,TPT

1229
9911224433
SQL>

1109
YES

22/APR/11

10

HNO:5-7-444,MPL

QUERY-3: Display the names of all passengers which are in cancellation


and waiting list.
DBMS LAB MANUAL

P a g e | 53
SQL> SELECT * FROM CANCELLATION;
PNR_NO
TICKET_NO JOURNEY_DA NO_OF_SEATS ADDRESS
----------------------------------------------------------------------------------------------------------------CONTACT_NO
STATUS
---------------------------------------1221
1101
25/MAR/11
4
HNO:1-A-501,ATP
9988776655
YES
1226
3355778899

1106
YES

05/APR/11

HNO:3-3-512,ATP

SQL> SELECT * FROM WAITINGLIST;


PNR_NO
TICKET_NO JOURNEY_DA NO_OF_SEATS ADDRESS
----------------------------------------------------------------------------------------------------------------CONTACT_NO
STATUS
---------------------------------------1224
1104
12/NOV/11
3
HNO:1-C-505,MPL
8855223311
YES
1225
9955116677

1105
YES

09/APR/11

HNO:2-1-222,TPT

1228
8822334466

1108
YES

20/APR/11

HNO:4-3-777,TPT

SQL> ( SELECT PNR_NO, TICKET_NO FROM CANCELLATION )


2 UNION
3 ( SELECT PNR_NO, TICKET_NO FROM WAITINGLIST );
PNR_NO TICKET_NO
-------------------------------------------1221
1101
1224
1104
1225
1105
1226
1106
1228
1108

SQL> ( SELECT PNR_NO, TICKET_NO FROM WAITINGLIST );

DBMS LAB MANUAL

P a g e | 54
PNR_NO TICKET_NO
---------------------------------------1224
1104
1225
1105
1228
1108
SQL> ( SELECT PNR_NO, TICKET_NO FROM CANCELLATION )
2 UNION ALL
3 ( SELECT PNR_NO, TICKET_NO FROM WAITINGLIST );
PNR_NO TICKET_NO
-------------------------------------1221
1101
1226
1106
1224
1104
1225
1105
1228
1108
SQL>

QUERY-4: Display Unique PNR_NO of all passengers.


SQL> SELECT * FROM PASSENGER;
PNR_NO
NAME
AGE G
PPNO
-----------------------------------------------------------------------------------------1221
CHAITANYA
28 M
A0502
1222
SHILPA
22 F
A0503
1223
KRISHNA
25 M
A0504
1224
MOHAN
26 M
A0505
1225
SAIDEEPTHI
24 F
A0506
1226
KIRAN
27 M
A0507
1227
HONEY
22 F
A0508
1228
ARUN
25 M
A0509
1229
MAMATHA
23 F
A0510
9 rows selected.

SQL> SELECT PNR_NO, NAME


2 FROM PASSENGER;
DBMS LAB MANUAL

P a g e | 55

PNR_NO NAME
---------------------------------------1221 CHAITANYA
1222 SHILPA
1223 KRISHNA
1224 MOHAN
1225 SAIDEEPTHI
1226 KIRAN
1227 HONEY
1228 ARUN
1229 MAMATHA
9 rows selected.
SQL>

QUERY-5: Display all the names of Male (M) all passengers only.
SQL> SELECT NAME FROM PASSENGER
2 WHERE GENDER='M';
NAME
--------------CHAITANYA
KRISHNA
MOHAN
KIRAN
ARUN
SQL>

QUERY-6: Display the Ticket Numbers and Names of all passengers only.
SQL> SELECT P.NAME, R.TICKET_NO
2 FROM PASSENGER P, RESERVATION R
3 WHERE R.PNR_NO = P.PNR_NO ;

NAME
TICKET_NO
------------------------------------------------------CHAITANYA
1101
DBMS LAB MANUAL

P a g e | 56
SHILPA
KRISHNA
MOHAN
SAIDEEPTHI
KIRAN
HONEY
ARUN
MAMATHA

1102
1103
1104
1105
1106
1107
1108
1109

9 rows selected.
SQL>

QUERY-7: Find the Ticket Numbers of passengers whose name


start with K.
SQL> SELECT P.NAME, R.TICKET_NO
2 FROM PASSENGER P, RESERVATION R
3 WHERE (R.PNR_NO = P.PNR_NO) AND (P.NAME LIKE 'K%');
NAME
TICKET_NO
------------------------------------------------KRISHNA
1103
KIRAN
1106
SQL>

QUERY-8: Find the Ticket Numbers of passengers whose name


ends with A.
SQL> SELECT P.NAME, R.TICKET_NO
2 FROM PASSENGER P, RESERVATION R
3 WHERE (R.PNR_NO = P.PNR_NO) AND (P.NAME LIKE '%A');
NAME
TICKET_NO
-------------------------------------------------CHAITANYA
1101
SHILPA
1102
KRISHNA
1103
MAMATHA
1109
SQL>

QUERY-9: Find the Ticket Numbers of passengers whose names which has
AI in middle or ends with A.
DBMS LAB MANUAL

P a g e | 57

SQL> SELECT P.NAME, R.TICKET_NO


2 FROM PASSENGER P, RESERVATION R
3 WHERE (R.PNR_NO = P.PNR_NO) AND
4 (P.NAME LIKE '%AI%' OR P.NAME LIKE '%A');
NAME
TICKET_NO
-----------------------------------------------CHAITANYA
1101
SHILPA
1102
KRISHNA
1103
SAIDEEPTHI
1105
MAMATHA
1109
SQL>

QUERY-10: Find the Ticket Numbers of passengers whose names which


starts with S and AI in middle and ends with I.
SQL> SELECT P.NAME, R.TICKET_NO
2 FROM PASSENGER P, RESERVATION R
3 WHERE (R.PNR_NO = P.PNR_NO) AND
4 (P.NAME LIKE 'S%' AND P.NAME LIKE '%AI%' AND P.NAME LIKE '%I');
NAME
TICKET_NO
----------------------------------------------SAIDEEPTHI
1105
SQL>

QUERY-11: Find the Names of passengers whose age is between 20 and 25.
SQL> SELECT * FROM PASSENGER;

PNR_NO NAME
AGE G PPNO
---------------------------------------------------------------------------------1221 CHAITANYA
28 M A0502
DBMS LAB MANUAL

P a g e | 58
1222 SHILPA
1223 KRISHNA
1224 MOHAN
1225 SAIDEEPTHI
1226 KIRAN
1227 HONEY
1228 ARUN
1229 MAMATHA

22 F
25 M
26 M
24 F
27 M
22 F
25 M
23 F

A0503
A0504
A0505
A0506
A0507
A0508
A0509
A0510

9 rows selected.
SQL> SELECT NAME FROM PASSENGER
2 WHERE AGE BETWEEN 20 AND 25;
NAME
--------------SHILPA
KRISHNA
SAIDEEPTHI
HONEY
ARUN
MAMATHA
6 rows selected.

QUERY-12: Find all the passengers names beginning with S.


SQL> SELECT * FROM PASSENGER;
PNR_NO NAME
AGE G PPNO
---------------------------------------------------------------------------------1221 CHAITANYA
28 M A0502
1222 SHILPA
22 F A0503
1223 KRISHNA
25 M A0504
1224 MOHAN
26 M A0505
1225 SAIDEEPTHI
24 F A0506
1226 KIRAN
27 M A0507
1227 HONEY
22 F A0508
1228 ARUN
25 M A0509
1229 MAMATHA
23 F A0510
9 rows selected.
SQL> SELECT NAME FROM PASSENGER
2 WHERE NAME LIKE 'S%';

DBMS LAB MANUAL

P a g e | 59
NAME
--------------SHILPA
SAIDEEPTHI

QUERY-13: Display the sorted list of passengers names.


SQL> SELECT * FROM PASSENGER;
PNR_NO NAME
AGE G PPNO
---------------------------------------------------------------------------------1221 CHAITANYA
28 M A0502
1222 SHILPA
22 F A0503
1223 KRISHNA
25 M A0504
1224 MOHAN
26 M A0505
1225 SAIDEEPTHI
24 F A0506
1226 KIRAN
27 M A0507
1227 HONEY
22
F A0508
1228 ARUN
25 M A0509
1229 MAMATHA
23 F A0510
9 rows selected.
SQL> SELECT NAME
2 FROM PASSENGER
3 ORDER BY NAME;
NAME
--------------ARUN
CHAITANYA
HONEY
KIRAN
KRISHNA
MAMATHA
MOHAN
SAIDEEPTHI
SHILPA
9 rows selected.
SQL>
*****************************************
LAB-PROGRAM NO:7
DBMS LAB MANUAL

P a g e | 60

Roadways Travel System - Queries using Aggregate Functions


AIM: Queries using Aggregate functions on database tables (i.e., BUS, TICKET,
PASSENGER, RESERVATION, CANCELLATION, And WAITINGLIST)
( i.e. COUNT, MIN, MAX, SUM & AVG ), GROUP BY, HAVING & creation and
dropping of views.

AGGREGATE FUNCTIONS
Aggregate functions are functions that take a collection of values as
INPUT and return a SINGLE value.
COUNT The number of rows containing NON-NULL values.
MIN

The minimum attribute value encountered in a given column.

MAX

The maximum attribute value encountered in a given column.

SUM

The sum of all values for a given column.

AVG

The arithmetic mean (Average) for a Specified column.

COUNT This function is used to Tally (i.e. Count) the number of NONNULL values of an attribute

Queries using Aggregate functions


QUERY-1: Find number of seats booked for each PNR_NO using
ORDER BY clause.
SQL> SELECT PNR_NO, NO_OF_SEATS
2 FROM RESERVATION
3 ORDER BY PNR_NO;

DBMS LAB MANUAL

P a g e | 61
PNR_NO NO_OF_SEATS
---------------------------------------1221
4
1222
2
1223
6
1224
3
1225
4
1226
1
1227
6
1228
4
1229
10
9 rows selected.
SQL>

QUERY-2: Find the number of DISTINCT Passenger Numbers that are


present.
SQL> SELECT COUNT ( DISTINCT P.NAME )
2 FROM PASSENGER P;
COUNT(DISTINCTP.NAME)
--------------------9
SQL>

QUERY-3: Find the number of Tickets booked for each passenger where the
number of seats is greater than one (i.e. >1).
SQL> SELECT COUNT( DISTINCT R.TICKET_NO)
2 FROM RESERVATION R
3 WHERE NO_OF_SEATS > 1
4 ORDER BY PNR_NO ASC;
COUNT(DISTINCT R.TICKET_NO)
------------------------------------------------8
SQL>

DBMS LAB MANUAL

P a g e | 62

QUERY-4: Find the total number of cancelled seats.


SQL> SELECT * FROM CANCELLATION;
PNR_NO TICKET_NO JOURNEY_DA NO_OF_SEATS ADDRESS
-----------------------------------------------------------------------------------------------------CONTACT_NO STATUS
------------------------------------1221
1101
25/MAR/11
4
HNO:1-A-501,ATP
9988776655
YES
1226
3355778899

106
YES

05/APR/11

HNO:3-3-512,ATP

SQL> SELECT SUM( C.NO_OF_SEATS )


2 FROM CANCELLATION C
3 WHERE STATUS='YES';
SUM(C.NO_OF_SEATS)
------------------------------------5
SQL>

QUERY-5: Display different travelling positions available for AC Buses in


decreasing order in Roadways Travel System.
SQL> SELECT BUS_NO, SOURCE, DESTINATION
2 FROM BUS
3 WHERE BUS_TYPE='AC'
4 ORDER BY BUS_NO DESC;
BUS_NO
SOURCE
DESTINATION
--------------------------------------------------------------------------AP02-7777 KADIRI
SHIRIDI
AP02-6666 BANGALORE
HYDERABAD
AP02-4444 MADANAPALI OOTY
AP02-3333 HINDUPUR
TIRUPATI
AP02-1111 ANANTAPUR
HYDERABAD
SQL>

DBMS LAB MANUAL

P a g e | 63

QUERY-6: Display list of passenger numbers present in the passenger and


cancellation tables using UNION operator
SQL> ( SELECT P.PNR_NO FROM PASSENGER P )
2 UNION
3 ( SELECT C.PNR_NO FROM CANCELLATION C );
PNR_NO
----------------------1221
1222
1223
1224
1225
1226
1227
1228
1229
9 rows selected.
SQL>

QUERY-7: Display total number of buses available in BUS table.


SQL> SELECT COUNT(*)
2 FROM BUS;
COUNT(*)
-------------------10
SQL>

QUERY-8: Find the Average Age of all passengers.


SQL> SELECT AVG(P.AGE)
2 FROM PASSENGER P;
AVG(P.AGE)
---------24.6666667
SQL>

DBMS LAB MANUAL

P a g e | 64

QUERY-9: Find the Minimum Age among all passengers.


SQL> SELECT MIN(P.AGE)
2 FROM PASSENGER P;
MIN(P.AGE)
---------22
SQL>

QUERY-10: Find the Maximum Age among all passengers.


SQL> SELECT MIN(P.AGE) AS MINIMUM_AGE
2 FROM PASSENGER P;
MINIMUM_AGE
----------22
SQL>

QUERY-11: Display all passengers whose age between 20 and 25 in


decreasing order of their names.
SQL> SELECT P.NAME AS NAME, P.AGE AS AGE
2 FROM PASSENGER P
3 WHERE AGE BETWEEN 20 AND 25
4 ORDER BY NAME DESC;
NAME
AGE
-------------------------------------SHILPA
22
SAIDEEPTHI
24
MAMATHA
23
KRISHNA
25
HONEY
22
ARUN
25
6 rows selected.
SQL>

DBMS LAB MANUAL

P a g e | 65

Views
QUERY-12: Creation of a view, Displaying the view, Dropping of view by
using the following procedure using BUS and TICKET tables.
SQL> CREATE VIEW BUS_TICKET
2 AS SELECT B.BUS_NO, B.BUS_TYPE, T.TICKET_NO,
T.JOURNEY_DATE,T.DEP_TIME
3 FROM BUS B, TICKET T
4 WHERE BUS_TYPE='AC'AND T.BUS_NO=B.BUS_NO;
View created.
SQL> SELECT * FROM BUS_TICKET;
BUS_NO BUS_TYPE TICKET_NO JOURNEY_DA DEP_TIME
---------------------------------------------------------------------------------------------------AP02-1111
AC
1101
25/MAR/11
10:30 PM
AP02-3333
AC
1103
22/JUN/11
11:30 AM
AP02-4444
AC
1104
12/NOV/11
12:30 PM
AP02-6666
AC
1106
05/APR/11
07:45 AM
AP02-7777
AC
1107
10/APR/11
05:30 AM
SQL>
SQL> DROP VIEW BUS_TICKET;
View dropped.
SQL>

*****************************************

DBMS LAB MANUAL

P a g e | 66

LAB-PROGRAM NO:8
Roadways Travel System - PRACTICING JOIN OPERRATIONS
AIM: JOIN OPERRATIONS ON DATABASE TABLES i.e

NATURAL JOIN
INNER JOIN
OUTER JOIN
LEFT OUTER JOIN
RIGHT OUTER JOIN
FULL OUTER JOIN

JOINS: A join is a query in which data is retrieved from two or more tables.
A join matches data from two or more tables, based on the values of one or
more columns in each table.
SQL> create table employee(emp_name varchar(15), city varchar(10));
Table created.
SQL> edit
Wrote file afiedt.buf
1 create table employee_salary(emp_name varchar(15), dept_name
varchar(15),
2* salary decimal(8,2) )
SQL> /
Table created.
SQL> desc employee
Name
Null? Type
----------------------------------------- -------- ---------------------------EMP_NAME
CITY

VARCHAR2(15)
VARCHAR2(10)
DBMS LAB MANUAL

P a g e | 67

SQL> desc employee_salary


Name
Null? Type
----------------------------------------- -------- ---------------------------EMP_NAME
DEPT_NAME
SALARY

VARCHAR2(15)
VARCHAR2(15)
NUMBER(8,2)

INSERTING VALUES:
SQL> edit
Wrote file afiedt.buf
1* insert into employee values('&emp_name','&dept_name')
SQL> /
Enter value for emp_name: hari
Enter value for dept_name: pune
old 1: insert into employee values('&emp_name','&dept_name')
new 1: insert into employee values('hari','pune')
1 row created.
SQL> /
Enter value for emp_name: om
Enter value for dept_name: mumbai
old 1: insert into employee values('&emp_name','&dept_name')
new 1: insert into employee values('om','mumbai')
1 row created.
SQL> run
1* insert into employee values('&emp_name','&dept_name')
Enter value for emp_name: smith
Enter value for dept_name: hyd
old 1: insert into employee values('&emp_name','&dept_name')
new 1: insert into employee values('smith','hyd')
1 row created.
DBMS LAB MANUAL

P a g e | 68

SQL> /
Enter value for emp_name: jay
Enter value for dept_name: banglore
old 1: insert into employee values('&emp_name','&dept_name')
new 1: insert into employee values('jay','banglore')
1 row created.
SQL> insert into employee_salary
values('&emp_name','&dept_name',&salary);
Enter value for emp_name: hari
Enter value for dept_name: computer
Enter value for salary: 10000
old 1: insert into employee_salary
values('&emp_name','&dept_name',&salary)
new 1: insert into employee_salary values('hari','computer',10000)
1 row created.
SQL> run
1* insert into employee_salary
values('&emp_name','&dept_name',&salary)
Enter value for emp_name: om
Enter value for dept_name: it
Enter value for salary: 70000
old 1: insert into employee_salary
values('&emp_name','&dept_name',&salary)
new 1: insert into employee_salary values('om','it',70000)
1 row created.
SQL> /
Enter value for emp_name: bill
Enter value for dept_name: computer
Enter value for salary: 8000
old 1: insert into employee_salary
values('&emp_name','&dept_name',&salary)
new 1: insert into employee_salary values('bill','computer',8000)

DBMS LAB MANUAL

P a g e | 69

1 row created.
SQL> /
Enter value for emp_name: jay
Enter value for dept_name: it
Enter value for salary: 5000
old 1: insert into employee_salary
values('&emp_name','&dept_name',&salary)
new 1: insert into employee_salary values('jay','it',5000)
1 row created.
SQL> select * from employee;
EMP_NAME
--------------hari
om
smith
jay

CITY
---------pune
mumbai
hyd
banglore

SQL> select * from employee_salary;


EMP_NAME
--------------hari
om
bill
jay

DEPT_NAME
SALARY
-----------------------computer
10000
it
70000
computer
8000
it
5000

INNER JOIN: Inner Join returns the matching rows from the tables that
being joined
SQL> edit
Wrote file afiedt.buf
1 select employee.emp_name,employee_salary.salary
2 from employee inner join employee_salary
3* on employee.emp_name= employee_salary.emp_name
DBMS LAB MANUAL

P a g e | 70

SQL> /
EMP_NAME
--------------hari
om
jay

SALARY
---------10000
70000
5000

SQL> edit
Wrote file afiedt.buf
1 select *
2 from employee inner join employee_salary
3* on employee.emp_name= employee_salary.emp_name
SQL> /
EMP_NAME CITY EMP_NAME DEPT_NAME
--------------- ---------- ----------------------------hari
pune
hari
computer
om
mumbai
om
it
jay
banglore
jay
it

SALARY
---------10000
70000
5000

OUTER JOINS
LEFT OUTER JOIN: The left outer join returns matching rows from the
tables being joined, and also non-matching rows from the left table in the
result and places null values in the attributes that come from the right table.
SQL> edit
Wrote file afiedt.buf
1 select employee.emp_name,salary
2 from employee left outer join employee_salary
3* on employee.emp_name=employee_salary.emp_name
SQL> /

DBMS LAB MANUAL

P a g e | 71

EMP_NAME
--------------hari
om
jay
smith

SALARY
---------10000
70000
5000

RIGHT OUTER JOIN: The right outer join returns matching rows from
the tables being joined, and also non-matching rows from the right table in
the result and places null values in the attributes that come from the left
table.
SQL> edit
Wrote file afiedt.buf
1 select *
2 from employee right outer join employee_salary
3* on employee.emp_name=employee_salary.emp_name
4 /
EMP_NAME CITY EMP_NAME
--------------- ---------- --------------hari
pune
hari
om
mumbai
om
jay
banglore
jay
bill

DEPT_NAME
--------------computer
it
it
computer

SQL>
SQL> edit
Wrote file afiedt.buf
1 select employee_salary.emp_name,city,salary
2 from employee right outer join employee_salary
3* on employee.emp_name=employee_salary.emp_name
SQL> /
EMP_NAME
---------------

CITY
----------

SALARY
---------DBMS LAB MANUAL

SALARY
---------10000
70000
5000
8000

P a g e | 72

hari
om
jay
bill

pune
mumbai
banglore

10000
70000
5000
8000

SQL> edit
Wrote file afiedt.buf
1 select employee.emp_name,city,salary
2 from employee right outer join employee_salary
3* on employee.emp_name=employee_salary.emp_name
SQL> /
EMP_NAME
--------------hari
om
jay

CITY
---------pune
mumbai
banglore

SALARY
---------10000
70000
5000
8000

SQL> edit
Wrote file afiedt.buf
1 select employee.emp_name,city,dept_name,salary
2 from employee right outer join employee_salary
3* on employee.emp_name=employee_salary.emp_name
SQL> /
EMP_NAME
--------------hari
om
jay

CITY
DEPT_NAME
-----------------------pune
computer
mumbai
it
banglore
it
computer

SALARY
---------10000
70000
5000
8000

FULL OUTER JOIN: The full outer join returns matching rows from the
tables being joined, and also non-matching rows from the right table and
left table in the result and places null values in the attributes that come from
the left table and right table.
DBMS LAB MANUAL

P a g e | 73

SQL> edit
Wrote file afiedt.buf
1 select employee.emp_name,city,dept_name,salary
2 from employee full outer join employee_salary
3* on employee.emp_name=employee_salary.emp_name
SQL> /
EMP_NAME CITY
--------------- ---------hari
pune
om
mumbai
jay
banglore
smith
hyd

DEPT_NAME
--------------computer
it
it
computer

SALARY
---------10000
70000
5000
8000

NATURAL JOIN:
SQL> edit
Wrote file afiedt.buf
1 select *
2* from employee natural join employee_salary
3 /
EMP_NAME
CITY
-----------------------hari
pune
om
mumbai
jay
banglore

DEPT_NAME
--------------computer
it
it

SALARY
---------10000
70000
5000

SQL> edit
Wrote file afiedt.buf
1 select *
2* from employee natural left outer join employee_salary
SQL> /
DBMS LAB MANUAL

P a g e | 74

EMP_NAME
--------------hari
om
jay
smith

CITY
DEPT_NAME SALARY
---------- -----------------------pune
computer
10000
mumbai it
70000
banglore it
5000
hyd

SQL> edit
Wrote file afiedt.buf
1 select *
2* from employee natural right outer join employee_salary
SQL> /
EMP_NAME
--------------hari
om
jay
bill

CITY
DEPT_NAME SALARY
---------- -----------------------pune
computer
10000
mumbai
it
70000
banglore it
5000
computer
8000

SQL> edit
Wrote file afiedt.buf
1 select *
2* from employee natural full outer join employee_salary
SQL> /
EMP_NAME
--------------hari
om
jay
smith
bill

CITY
DEPT_NAME
---------- --------------pune
computer
mumbai it
banglore it
hyd
computer

SALARY
---------10000
70000
5000
8000

SQL>
***********************************

DBMS LAB MANUAL

P a g e | 75

LAB-PROGRAM NO:10
Roadways Travel System - PL/SQL PROGRAM
AIM: Write a PL/SQL program for reversing a given number.

SQL> set serveroutput on;


SQL> declare
2
3
given_no number(8);
4
str_length number(8);
5
reverse_no varchar2(8);
6
7 begin
8
given_no:=&given_no;
9
str_length :=length(given_no);
10
11
for cntr in reverse 1..str_length
12
13
loop
14
15
reverse_no := reverse_no || substr(given_no,cntr,1);
16
17
end loop;
18
19
dbms_output.put_line('The given number is' || given_no );
20
dbms_output.put_line('The given number is' || reverse_no );
21
22 end;
23
24 /
Enter value for given_no: 1234
old 8:
given_no:=&given_no;
new 8:
given_no:=1234;
The given number is1234
The given number is4321
PL/SQL procedure successfully completed.
****************************************
DBMS LAB MANUAL

P a g e | 76

LAB-PROGRAM NO:11
Roadways Travel System - PL/SQL PROGRAM
AIM: Write a PL/SQL program using cursor technique on employee database.

CURSOR: There are 4 important operations i.e


Cursor Declaration
Open Cursor statement
Fetch statement
Close cursor statement
SQL> DESC EMPLOYEE;
Name
Null? Type
----------------------------------------- -------- ---------------------------EMPNO
NUMBER(5)
SALARY
NUMBER(10,2)
DEPTNO
NUMBER(5)
SQL> INSERT INTO EMPLOYEE VALUES(&EMPNO,&SALARY,&DEPTNO) ;
Enter value for empno: 1001
Enter value for salary: 8000.25
Enter value for deptno: 10
old 1: INSERT INTO EMPLOYEE VALUES(&EMPNO,&SALARY,&DEPTNO)
new 1: INSERT INTO EMPLOYEE VALUES(1001,8000.25,10)
1 row created.
SQL> /
Enter value for empno: 1002
Enter value for salary: 1500.00
Enter value for deptno: 10
old 1: INSERT INTO EMPLOYEE VALUES(&EMPNO,&SALARY,&DEPTNO)
new 1: INSERT INTO EMPLOYEE VALUES(1002,1500.00,10)
1 row created.
SQL> /
Enter value for empno: 1003
Enter value for salary: 7555.75
Enter value for deptno: 10
old 1: INSERT INTO EMPLOYEE VALUES(&EMPNO,&SALARY,&DEPTNO)
new 1: INSERT INTO EMPLOYEE VALUES(1003,7555.75,10)
DBMS LAB MANUAL

P a g e | 77

1 row created.
SQL> RUN
1* INSERT INTO EMPLOYEE VALUES(&EMPNO,&SALARY,&DEPTNO)
Enter value for empno: 1004
Enter value for salary: 6000.25
Enter value for deptno: 20
old 1: INSERT INTO EMPLOYEE VALUES(&EMPNO,&SALARY,&DEPTNO)
new 1: INSERT INTO EMPLOYEE VALUES(1004,6000.25,20)
1 row created.
SQL> /
Enter value for empno: 1005
Enter value for salary: 3550.25
Enter value for deptno: 22
old 1: INSERT INTO EMPLOYEE VALUES(&EMPNO,&SALARY,&DEPTNO)
new 1: INSERT INTO EMPLOYEE VALUES(1005,3550.25,22)
1 row created.
SQL> SELECT * FROM EMPLOYEE;
EMPNO SALARY DEPTNO
---------- ---------- ---------1001 8000.25
10
1002
1500
10
1003 7555.75
10
1004 6000.25
20
1005 3550.25
22
SQL> DESC EMP_RAISE;
Name
Null? Type
----------------------------------------- -------- ---------------------------EMPNO
NUMBER(5)
CURR_DATE
DATE
RAISE_SALARY
NUMBER(10,2)
SQL> SELECT * FROM EMP_RAISE;
no rows selected

DBMS LAB MANUAL

P a g e | 78

SQL> declare

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

cursor c_emp is select empno,salary from employee where deptno=10;


num_empno employee.empno%type;
curr_salary employee.salary%type;
begin
open c_emp;
if c_emp%isopen then
loop
fetch c_emp into num_empno,curr_salary;
exit when c_emp%notfound;
update employee set salary=curr_salary+(curr_salary*0.05)
where empno=num_empno;
insert into emp_raise values(num_empno,sysdate,curr_salary*0.05);
end loop;
commit;
close c_emp;
else
dbms_output.put_line('unable to open the cursor');
end if;
end;
/

PL/SQL procedure successfully completed.

DBMS LAB MANUAL

P a g e | 79

SQL> SELECT * FROM EMP_RAISE;


EMPNO CURR_DATE RAISE_SALARY
---------- --------- -----------1001 29-MAR-11
400.01
1002 29-MAR-11
75
1003 29-MAR-11
377.79
SQL> SELECT * FROM EMPLOYEE;
EMPNO SALARY DEPTNO
---------- ---------- ---------1001 8400.26
10
1002
1575
10
1003 7933.54
10
1004 6000.25
20
1005 3550.25
22
SQL>
***********************************************************

DBMS LAB MANUAL

P a g e | 80

LAB-PROGRAM NO:12
Writing PL/SQL block for insertion into a table.
To write a PL/SQL block f or inserting rows into EMPDET table with
the following
Calculations:
HRA=50% OF BASIC
DA=20% OF BASIC
PF=7% OF BASIC
NETPAY=BASIC+DA+HRA-PF
INPUT
DECLARE
ENO1 empdet.eno%type;
ENAME1 empdet.name%type;
DEPTNO1 empdet.deptno%type;
BASIC1 empdet.basic%type;
HRA1 empdet.HRA%type;
DA1 empdet.DA%type;
PF1 empdet.pf%type;
NETPAY1 empdet.netpay%type;
BEGIN
ENO1:=&ENO1;
ENAME1:='&ENAME1';
DEPTNO1:=&DEPTNO1;
BASIC1:=&BASIC1;
HRA1:=(B ASIC1*50)/100;
DA1:=(BASIC1*20)/100;
PF1:=(BASIC1*7)/100;
NETPAY1:=BASIC1+HRA1+DA1-PF1;
INSERT INTO EMPDET VALUES (ENO1, ENAME1, DEPTNO1, BASIC1,
HRA1,

DBMS LAB MANUAL

P a g e | 81
DA1, PF1, NETPAY1);
END;

RESULT:
SQL> @BASIC
Enter value for eno1: 104
old 11: ENO1:=&ENO1;
new 11: ENO1:=104;
Enter value for ename1: SRINIVAS REDDY
old 12: ENAME1:='&ENAME1';
new 12: ENAME1:='SRINIVAS REDDY';
Enter value for deptno1: 10
old 13: DEPTNO1:=&DEPTNO1;
new 13: DEPTNO1:=10;
Enter value for basic1: 6000
old 14: BASIC1:=&BASIC1;
new 14: BASIC1:=6000;
PL/SQL procedure successfully completed.

SQL>/
Enter value for eno1: 105
old 11: ENO1:=&ENO1;
new 11: ENO1:=105;
Enter value for ename1: CIRAJ
old 12: ENAME1:='&ENAME1';
new 12: ENAME1:='CIRAJ';
Enter value for deptno1: 10
old 13: DEPTNO1:=&DEPTNO1;
new 13: DEPTNO1:=10;
Enter value for basic1: 6000
old 14: BASIC1:=&BASIC1;
new 14: BASIC1:=6000;
DBMS LAB MANUAL

P a g e | 82

PL/SQL procedure successfully completed.


SQL> SELECT * FROM EMPDET;
RESULT
ENO NAME
DEPTNO
BASIC
HRA
DA
PF NETPAY
--------- ------------------------------ --------- --------- --------- --------- ------------------------------101 SANTOSH
10
5000
2500
1000
350
8150
102 SHANKAR
20
5000
2500
1000
350
8150
103 SURESH
20
5500
2750
1100
385
8965
104 SRINIVASA REDDY
10
6000
3000
1200
420
9780
105 CIRAJ
10
6000
3000
1200
420
9780

DBMS LAB MANUAL

P a g e | 83

LAB-PROGRAM NO:13
Armstrong number
To write a PL/SQL block to check whether given num ber is
Armstrong or not.
INPUT
DECLARE
num number(5);
rem number(5);
s number(5):=0;
num1 number(5);
BEGIN
num:=&num;
num1:=num;
while(num>0)
loop
rem:=mod(num,10);
s:=s+power(rem,3);
num:=trunc(num/10);
End loop;
if (s=num1)then
DBMS LAB MANUAL

P a g e | 84
dbms_RESULT.put_line(num1||' IS ARMSTRONG NUMBER ');
else
dbms_RESULT.put_line(num1||' IS NOT ARMSTRONG NUMBER ');
End if;
END;
/

RESULT:
SQL>@arm
Enter value for num: 153
old 7: num:=&num;
new 7: num:=153;
153 IS ARMSTRONG NUMBER
PL/SQL procedure successfully completed.
SQL> /
Enter value for num: 123
old 7: num:=&num;
new 7: num:=123;
123 IS NOT ARMSTRONG NUMBER
PL/SQL procedure successfully completed.

DBMS LAB MANUAL

P a g e | 85

LAB-PROGRAM NO:14
Writing a PL/SQL block for checking a number even or odd.
AIM: To write a PL/SQL block to check whether a given number is
Even or Odd.
INPUT
DECLARE
num number(5);
rem number;
BEGIN
num:=&num;
rem:=mod(num,2);
if rem=0
then
dbms_RESULT.put_line(' Number '||num| ' is Even');
else
dbms_RESULT.put_line(' Number '||num| ' is Odd');
end if;
END;
RESULT:
SQL>start even
Enter value for num: 6
DBMS LAB MANUAL

P a g e | 86
old 5: num:=&num;
new 5: num:=6;
Number 6 is Even
PL/SQL procedure successfully completed.
SQL> /
Enter value for num: 3
old 5: num:=&num;
new 5: num:=3;
Number 3 is Odd
PL/SQL procedure successfully completed.

LAB-PROGRAM NO:15
To write a PL/SQL block to find Sum of Digits of a given Number.
INPUT
DECLARE
num number(5);
rem number(5);
sm number(5):=0;
num1 number(5);
BEGIN
num:=&num;
num1:=num;
while(num>0) loop
rem:=mod(num,10);
sm:=sm+rem;
num:=trunc(num/10);
end loop;
dbms_RESULT.put_line('SUM OF DIGITS OF '| num1||' IS: '| sm);
end;
/
RESULT:
SQL> @sum
INPUT truncated to 2 characters
Enter value for num: 123
DBMS LAB MANUAL

P a g e | 87
old 7: num:=&num;
new 7: num:=123;
SUM OF DIGITS OF 123 IS: 6
PL/SQL procedure successfully completed.
SQL> @sum
INPUT truncated to 2 characters
Enter value for num: 456
old 7: num:=&num;
new 7: num:=456;
SUM OF DIGITS OF 456 IS: 15
PL/SQL procedure successfully completed.

LAB-PROGRAM NO:16
Writing PL/SQL triggers
To write a TRIGGER to ensure that DEPT TABLE does not contain duplicate of null
values in DEPTNO column.
INPUT
CREATE OR RELPLACE TRIGGER trig1 before insert on dept for each row
DECLARE
a number;
BEGIN
if(:new.deptno is Null) then
raise_application_error(-20001,'error::deptno cannot be null');
else
select count(*) into a from dept where deptno=:new.deptno;
if(a=1) then
raise_application_error(-20002,'error:: cannot have duplicate deptno');
end if;
end if;
END;
RESULT:

DBMS LAB MANUAL

P a g e | 88

SQL> @trigger
Trigger created.
SQL> select * from dept;
DEPTNO DNAME
LOC
--------- -------------- ------------10 ACCOUNTING NEW YORK
20 RESEARCH
DALLAS
30 SALES
CHICAGO
40 OPERATIONS BOSTON
SQL> insert into dept values(&deptnp,'&dname','&loc');
Enter value for deptnp: null
Enter value for dname: marketing
Enter value for loc: hyd
old 1: insert into dept values(&deptnp,'&dname','&loc')
new 1: insert into dept values(null,'marketing','hyd')
insert into dept values(null,'marketing','hyd')
*
ERROR at line 1:
ORA-20001: error::deptno cannot be null
ORA-06512: at "SCOTT.TRIG1", line 5
ORA-04088: error during execution of trigger 'SCOTT.TRIG1'
SQL> /
Enter value for deptnp: 10
Enter value for dname: manager
Enter value for loc: hyd
old 1: insert into dept values(&deptnp,'&dname','&loc')
new 1: insert into dept values(10,'manager','hyd')
insert into dept values(10,'manager','hyd')
*
ERROR at line 1:
ORA-20002: error:: cannot have duplicate deptno
ORA-06512: at "SCOTT.TRIG1", line 9

DBMS LAB MANUAL

P a g e | 89
ORA-04088: error during execution of trigger 'SCOTT.TRIG1'
SQL> /
Enter value for deptnp: 50
Enter value for dname: MARKETING
Enter value for loc: HYDERABAD
old 1: insert into dept values(&deptnp,'&dname','&loc')
new 1: insert into dept values(50,'MARKETING','HYDERAB AD')
1 row created.
SQL> select * from dept;

DEPTNO DNAME

LOC

--------- -------------- ------------10 ACCOUNTING NEW YORK


20 RESEARCH
DALLAS
30 SALES
CHICAGO
40 OPERATIONS BOSTON
50 MARKETING HYDE

DBMS LAB MANUAL

P a g e | 90

VIWA QUESTIONS
VIVA VOICE QUESTIONS AND ANSWERS
1. What is database?
A database is a logically coherent collection of data with some inherent meaning,
representing some aspect of real world and which is designed, built and populated with data
for a specific purpose.
2. What is DBMS?
It is a collection of programs that enables user to create and maintain a database. In other
words it is general-purpose software that provides the users with the processes of defining,
constructing and manipulating the database for various applications.
3. What is a Database system?
The database and DBMS software together is called as Database system.
4. Advantages of DBMS?
Redundancy is controlled.
Unauthorized access is restricted.
Providing multiple user interfaces.
Enforcing integrity constraints.
Providing backup and recovery.
5. Disadvantage in File Processing System?
Data redundancy & inconsistency.
DBMS LAB MANUAL

P a g e | 91
Difficult in accessing data.
Data isolation.
Data integrity.
Concurrent access is not possible.
Security Problems.
6. Describe the three levels of data abstraction?
The are three levels of abstraction:
Physical level: The lowest level of abstraction describes how data are stored.
Logical level: The next higher level of abstraction, describes what data are stored in
database and what relationship among those data.
View level: The highest level of abstraction describes only part of entire database.
7. Define the "integrity rules"
There are two Integrity rules.
Entity Integrity: States that Primar y key cannot have NULL value
Referential Integrity: States that Foreign Key can be either a NULL value or should be
Primary Key value of other relation.
8. What is extension and intension?
Extension It is the number of tuples present in a table at any instance. This is time dependent.
Intension
It is a constant value that gives the name, structure of table and the constraints laid on it.
11. What is Data Independence?
Data independence means that the application is independent of the storage structure and
access strategy of data. In other words, The ability to modify the schema definition in one
level should not affect the schema definition in the next higher level.
Two types of Data Independence:
Physical Data Independence: Modification in physical level should not affect the logical
level.
Logical Data Independence: Modification in logical level should affect the view level.
NOTE: Logical Data Independence is more difficult to achieve
12. What is a view? How it is related to data independence?
A view may be thought of as a virtual table, that is, a table that does not really exist in its
DBMS LAB MANUAL

P a g e | 92
own right but is instead derived from one or more underlying base table. In other words,
there is no stored file that direct represents the view instead a definition of view is stored in
data dictionary.
Growth and restructuring of base tables is not reflected in views. Thus the view can insulate
users from the effects of restructuring and growth in the database. Hence accounts for logical
data independence.
13. What is Data Model?
A collection of conceptual tools for describing data, data relationships data semantics and
constraints.

14. What is E-R model?


This data model is based on real world that consists of basic objects called entities and of
relationship among these objects. Entities are described in a database by a set of attributes.
15. What is Object Oriented model?
This model is based on collection of objects. An object contains values stored in instance
variables with in the object. An object also contains bodies of code that operate on the object.
These bodies of code are called methods. Objects that contain same types of values and the
same methods are grouped together into classes.
16. What is an Entity?
It is a 'thing' in the real world with an independent existence.
17. What is an Entity type?
It is a collection (set) of entities that have same attributes.
18. What is an Entity set?
It is a collection of all entities of particular entity type in the database.
19. What is an Extension of entity type?
The collections of entities of a particular entity type are grouped together into an entity set.
20. What is Weak Entity set?
An entity set may not have sufficient attributes to form a primary key, and its primary key
DBMS LAB MANUAL

P a g e | 93
compromises of its partial key and primary key of its parent entity, then it is said to be Weak
Entity set.
21. What is an attribute?
It is a particular property, which describes the entity.
22. What is a Relation Schema and a Relation?
A relation Schema denoted by R(A1, A2, , An) is made up of the relation name R and the
list of attributes Ai that it contains. A relation is defined as a set of tuples. Let r be the relation
which contains set tuples (t1, t2, t3, ..., tn). Each tuple is an ordered list of n-values t=(v1,v2,
..., vn).
23. What is degree of a Relation?
It is the number of attribute of its relation schema.
24. What is Relationship?
It is an association among two or more entities.
25. What is Relationship set?
The collection (or set) of similar relationships.
26. What is Relationship type?
Relationship type defines a set of associations or a relationship set among a given set of
entity types.
27. What is degree of Relationship type?
It is the number of entity type participating.
28. What is DDL (Data Definition Language)?
A data base schema is specifies by a set of definitions expressed by a special language called
DDL.
29. What is VDL (View Definition Language)?
It specifies user views and their mappings to the conceptual schema.
30. What is SDL (Storage Definition Language)?

DBMS LAB MANUAL

P a g e | 94
This language is to specify the internal schema. This language may specify the mapping
between two schemas.
31. What is Data Storage - Definition Language?
The storage structures and access methods used by database system are specified by a set of
definition in a special type of DDL called data storage-definition language.
32. What is DML (Data Manipulation Language)?
This language that enable user to access or manipulate data as organised by appropriate data
model.
Procedural DML or Low level: DML requires a user to specify what data are needed and
how to get those data.
Non-Procedural DML or High level: DML requires a user to specify what data are needed
without specif ying how to get those data.
33. What is DML Compiler?
It translates DML statements in a query language into low-level instruction that the query
evaluation engine can understand.
34. What is Query evaluation engine?
It executes low-level instruction generated by compiler.
35. What is DDL Interpreter?
It interprets DDL statements and records them in tables containing metadata.
36. What is Record-at-a-time?
The Low level or Procedural DML can specify and retrieve each record from a set of records.
This retrieve of a record is said to be Record-at-a-time.
37. What is Set-at-a-time or Set-oriented?
The High level or Non-procedural DML can specify and retrieve many records in a single
DML statement. This retrieve of a record is said to be Set-at-a-time or Set-oriented.
38. What is Relational Algebra?
It is procedural query language. It consists of a set of operations that take one or two relations
as input and produce a new relation.
DBMS LAB MANUAL

P a g e | 95

39. What is Relational Calculus?


It is an applied predicate calculus specifically tailored for relational databases proposed by
E.F. Codd. E.g. of languages based on it are DSL ALPHA, QUEL.
40. How does Tuple-oriented relational calculus differ from domain-oriented relat ional
calculus
The tuple-oriented calculus uses a tuple variables i.e., variable whose only permitted values
are tuples of that relation. E.g. QUEL
The domain-oriented calculus has domain variables i.e., variables that range over the
underlying domains instead of over relation. E.g. ILL, DEDUCE.
41. What is normalization?
It is a process of analysing the given relation schemas based on their Functional
Dependencies (FDs) and primary key to achieve the properties
Minimizing redundancy
Minimizing insertion, deletion and update anomalies.
42. What is Functional Dependency?
A Functional dependency is denoted by X Y between two sets of attributes X and Y that are
subsets of R specifies a constraint on the possible tuple that can form a relation state r of R.
The constraint is for any two tuples t1 and t2 in r if t1[X] = t2[X] then they have t1[Y] =
t2[Y]. This means the value of X component of a tuple uniquely determines the value of
component Y.
43. When is a functional dependency F said to be minimal?
Ever y dependency in F has a single attribute for its right hand side.
We cannot replace any dependency X A in F with a dependency Y A where Y is a proper
subset of X and still have a set of dependency that is equivalent to F.
We cannot remove any dependency from F and still have set of dependency that is
equivalent to F.
44. What is Multivalued dependency?
Multivalued dependency denoted by X Y specified on relation schema R, where X and Y are
both subsets of R, specifies the following constraint on any relation r of R: if two tuples t1
and t2 exist in r such that t1[X] = t2[X] then t3 and t4 should also exist in r with the

DBMS LAB MANUAL

P a g e | 96
following properties
t3[x] = t4[X] = t1[X] = t2[X]
t3[Y] = t1[Y] and t4[Y] = t2[Y]
t3[Z] = t2[Z] and t4[Z] = t1[Z]
where [Z = (R-(X U Y)) ]
45. What is Lossless join property?
It guarantees that the spurious tuple generation does not occur with respect to relation
schemas after decomposition.
46. What is 1 NF (Normal Form)?
The domain of attribute must include only atomic (simple, indivisible) values.
47. What is Fully Functional dependency?
It is based on concept of full functional dependency. A functional dependency X Y is full
functional dependency if removal of any attribute A from X means that the dependency does
not hold any more.
48. What is 2NF?
A relation schema R is in 2NF if it is in 1NF and every non-prime attribute A in R is fully
functionally dependent on primar y key.
49. What is 3NF?
A relation schema R is in 3NF if it is in 2NF and for every FD X A either of the following is
true
X is a Super-key of R.
A is a prime attribute of R.
In other words, if every non prime attribute is non-transitively dependent on primar y key.
50. What is BCNF (Boyce- Codd Normal Form)?
A relation schema R is in BCNF if it is in 3NF and satisfies an additional constraint that for
every FD X A, X must be a candidate key.
51. What is 4NF?
A relation schema R is said to be in 4NF if for ever y Multivalued dependency X Y that holds
over R, one of following is true
DBMS LAB MANUAL

P a g e | 97
X is subset or equal to (or) XY = R.
X is a super key.
52. What is 5NF?
A Relation schema R is said to be 5NF if for every join dependency {R1, R2, ..., Rn} that
holds R, one the following is true
Ri = R for some i.
The join dependency is implied by the set of FD, over R in which the lef t side is key of R.
53. What is Domain-Key Normal Form?
A relation is said to be in DKNF if all constraints and dependencies that should hold on the
the constraint can be enforced by simply enforcing the domain constraint and key constraint
on the relation.
54. What are partial, alternate,, artificial, compound and natural key?
Partial Key:
It is a set of attributes that can uniquely identify weak entities and that are related to same
owner entity. It is sometime called as Discriminator.
Alternate Key:
All Candidate Keys excluding the Primar y Key are known as Alternate Keys.
Artificial Key:
If no obvious key, either stand alone or compound is available, then the last resort is to
simply create a key, by assigning a unique number to each record or occurrence. Then this is
known as developing an artificial key.
Compound Key:
If no single data element uniquely identifies occurrences within a construct, then combining
multiple elements to create a unique identifier for the construct is known as creating a
compound key.
Natural Key:
When one of the data elements stored within a construct is utilized as the primary key, then it
is called the natural key.
55. What is indexing and what are the different kinds of indexing?
Indexing is a technique for determining how quickly specific data can be found.
Types:
Binar y search style indexing
B-Tree indexing
DBMS LAB MANUAL

P a g e | 98
Inverted list indexing
Memory resident table
Table indexing
56. What is system catalog or catalog relation? How is better known as?
A RDBMS maintains a description of all the data that it contains, information about every
relation and index that it contains. This information is stored in a collection of relations
maintained by the system called metadata. It is also called data dictionary.
57. What is meant by query optimization?
The phase that identifies an efficient execution plan for evaluating a query that has the least
estimated cost is referred to as query optimization.
58. What is join dependency and inclusion dependency?
Join Dependency:
A Join dependency is generalization of Multivalued dependency.A JD {R1, R2, ..., Rn} is
said to hold over a relation R if R1, R2, R3, ..., Rn is a lossless-join decomposition of R .
There is no set of sound and complete inference rules for JD.
Inclusion Dependency:
An Inclusion Dependency is a statement of the form that some columns of a relation are
contained in other columns. A foreign key constraint is an example of inclusion dependency.
59. What is durability in DBMS?
Once the DBMS informs the user that a transaction has successfully completed, its effects
should persist even if the system crashes before all its changes are reflected on disk. This
property is called durability.
60. What do you mean by atom icity and aggregation?
Atomicity:
Either all actions are carried out or none are. Users should not have to worry about the effect
of incomplete transactions. DBMS ensures this by undoing the actions of incomplete
transactions.
Aggregation:
A concept which is used to model a relationship between a collection of entities and
relationships. It is used when we need to express a relationship among relationships.
61. What is a Phantom Deadlock?
DBMS LAB MANUAL

P a g e | 99
In distributed deadlock detection, the delay in propagating local information might cause the
deadlock detection algorithms to identif y deadlocks that do not really exist. Such situations
are called phantom deadlocks and they lead to unnecessary aborts.
62. What is a checkpoint and When does it occur?
A Checkpoint is like a snapshot of the DBMS state. By taking checkpoints, the DBMS can
reduce the amount of work to be done during restart in the event of subsequent crashes.
63. What are the different phases of transaction?
Different phases are
Analysis phase
Redo Phase
Undo phase
64. What do you mean by f lat file database?
It is a database in which there are no programs or user access languages. It has no cross-file
capabilities but is user-friendly and provides user-interface management.
65. What is "transparent DBMS"?
It is one, which keeps its Physical Structure hidden from user.
66. Brief theory of Network, Hierarchical schema as and their properties
Network schema uses a graph data structure to organize records example for such a database
management system is CTCG while a hierarchical schema uses a tree data structure example
for such a system is IMS.
67. What is a query?
A query with respect to DBMS relates to user commands that are used to interact with a database.
The query language can be classified into data definition language and data
manipulation language.
68. What do you mean by Correlated subquery?
Subqueries, or nested queries, are used to bring back a set of rows to be used by the parent
quer y. Depending on how the subquery is written, it can be executed once for the parent
quer y or it can be executed once for each row returned by the parent query. If the subquery is
executed for each row of the parent, this is called a correlated subquery.
A correlated subquery can be easily identified if it contains any references to the parent

DBMS LAB MANUAL

P a g e | 100
subquery columns in its WHERE clause. Columns from the subquery cannot be referenced
anywhere else in the parent query. The following example demonstrates a non-correlated
subquery.
E.g. Select * From CUST Where '10/03/1990' IN (Select ODATE From ORDER Where
CUST.CNUM = ORDER.CNUM)
69. What are the primitive operations common to all record management systems?
Addition, deletion and modification.
70. Name the buffer in which all the commands that are typed in are stored
Edit Buffer
71. What are the unary operations in Relational Algebra?
PROJECTION and SELECTION.
72. Are the resulting relations of PRODUCT and JOIN operation the same?
No.
PRODUCT: Concatenation of every row in one relation with every row in another.
JOIN: Concatenation of rows from one relation and related rows from another.
73. What is RDBMS KERNEL?
Two important pieces of RDBMS architecture are the kernel, which is the software, and the
data dictionary, which consists of the system-level data structures used by the kernel to
manage the database
You might think of an RDBMS as an operating system (or set of subsystems), designed
specifically for controlling data access; its primar y functions are storing, retrieving, and
securing data. An RDBMS maintains its own list of authorized users and their associated
privileges; manages memory caches and paging; controls locking for concurrent resource
usage; dispatches and schedules user requests; and manages space usage within its tablespace structures.
74. Name the sub-systems of a RDBMS
I/O, Security, Language Processing, Process Control, Storage Management, Logging and
Recovery, Distribution Control, Transaction Control, Memory Management, Lock
Management
75. Which part of the RDBMS takes care of the data dictionary? How
DBMS LAB MANUAL

P a g e | 101
Data dictionar y is a set of tables and database objects that is stored in a special area of the
database and maintained exclusively by the kernel.
76. What is the job of the information stored in data-dictionary?
The information in the data dictionary validates the existence of the objects, provides access
to them, and maps the actual physical storage location.
77. Not only RDBMS takes care of locating data it also
determines an optimal access path to store or retrieve the data
76. How do you communicate with an RDBMS?
You communicate with an RDBMS using Structured Query Language (SQL)
78. Define SQL and state the differences between SQL and other conventional
programming Languages
SQL is a nonprocedural language that is designed specifically for data access operations on
normalized relational database structures. The primary difference between SQL and other
conventional programming languages is that SQL statements specify what data operations
should be performed rather than how to perform them.
85. What is database Trigger?
A database trigger is a PL/SQL block that can defined to automatically execute for insert,
update, and delete statements against a table. The trigger can e defined to execute once for
the entire statement or once for ever y row that is inserted, updated, or deleted. For any one
table, there are twelve events for which you can define database triggers. A database trigger
can call database procedures that are also written in PL/SQL.
86. Name two utilities that Oracle provides, which are use for backup and recovery.
Along with the RDBMS software, Oracle provides two utilities that you can use to back up
and restore the database. These utilities are Export and Import.
The Export utility dumps the definitions and data for the specified part of the database to an
operating system binar y file. The Import utility reads the file produced by an export,
recreates the definitions of objects, and inserts the data
If Export and Import are used as a means of backing up and recovering the database, all the
changes made to the database cannot be recovered since the export was performed. The best
you can do is recover the database to the time when the export was last performed.
DBMS LAB MANUAL

P a g e | 102

87. What are stored-procedures? And what are the advantages of using them .
Stored procedures are database objects that perform a user defined operation. A stored
procedure can have a set of compound SQL statements. A stored procedure executes the SQL
commands and returns the result to the client. Stored procedures are used to reduce network
traffic.
88. How are exceptions handled in PL /SQL? Give some of the internal exceptions' name
PL/SQL exception handling is a mechanism for dealing with run-time errors encountered
during procedure execution. Use of this mechanism enables execution to continue if the error
is not severe enough to cause procedure termination.
The exception handler must be defined within a subprogram specification. Errors cause the
Program to raise an exception with a transfer of control to the exception-handler block. After
the exception handler executes, control returns to the block in which the handler was defined.
If there are no more executable statements in the block, control returns to the caller.
User-Defined Exceptions
PL/SQL enables the user to define exception handlers in the declarations area of subprogram
specifications. User accomplishes this by naming an exception as in the following example:
ot_failure EXCEPTION;
In this case, the exception name is ot_failure. Code associated with this handler is written in
the EXCEPTION specification area as follows:
EXCEPTION
when OT_FAILURE then
out_status_code := g_out_status_code;
out_msg := g_out_msg;
The following is an example of a subprogram exception:
EXCEPTION
when NO_DATA_FOUND then
g_out_status_code := 'FAIL';
RAISE ot_failure;
Within this exception is the RAISE statement that transfers control back to the ot_failure
exception handler. This technique of raising the exception is used to invoke all user-defined
exceptions.
System-Defined Exceptions
Exceptions internal to PL/SQL are raised automatically upon error. NO_DATA_FOUND is a
DBMS LAB MANUAL

P a g e | 103
system-defined exception. Table below gives a complete list of internal exceptions.
PL/SQL internal exceptions.
PL/SQL internal exceptions.
Exception Name Oracle Error
CURSOR_ALREADY_OPEN ORA-06511
DUP_VAL_ON_INDEX ORA-00001
INVALID_CURSOR ORA-01001
INVALID_NUMBER OR A-01722
LOGIN_DENIED ORA-01017
NO_DATA_FOUND ORA-01403
NOT_LOGGED_ON ORA-01012
PROGRAM_ERROR ORA-06501
STORAGE_ERROR ORA-06500
TIMEOUT_ON_RESOURCE ORA-00051
TOO_MANY_ROWS OR A-01422
TRANSACTION_BACKED_OUT ORA-00061
VALUE_ERROR ORA-06502
ZERO_DIVIDE ORA-01476
In addition to this list of exceptions, there is a catch-all exception named OTHERS that traps
all errors for which specific error handling has not been established.
89. Does PL/SQL support "overloading"? Explain
The concept of overloading in PL/SQL relates to the idea that you can define procedures and
functions with the same name. PL/SQL does not look only at the referenced name, however,
to resolve a procedure or function call. The count and data types of for mal parameters are
also considered.
PL/SQL also attempts to resolve any procedure or function calls in locally defined packages
before looking at globally defined packages or internal functions. To further ensure calling
the proper procedure, you can use the dot notation. Prefacing a procedure or function name
with the package name fully qualifies any procedure or function reference.

92. A B C is a set of attributes. The functional dependency is as follows


DBMS LAB MANUAL

P a g e | 104
AB -> B
AC -> C
C -> B
a) is in 1NF
b) is in 2NF
c) is in 3NF
d) is in BCNF
(a) is in 1NF since (AC)+ = { A, B, C} hence AC is the primary key. Since C B is a FD
given, where neither C is a Key nor B is a prime attribute, this it is not in 3NF. Further B is
not functionally dependent on key AC thus it is not in 2NF. Thus the given FDs is in 1NF.
96. What is Storage Manager?
It is a program module that provides the interface between the low-level data stored in
database, application programs and queries submitted to the system.

97. What is Buffer Manager?


It is a program module, which is responsible for fetching data from disk storage into main
memory and deciding what data to be cache in memor y.
98. What is Transaction Manager?
It is a program module, which ensures that database, remains in a consistent state despite
system failures and concurrent transaction execution proceeds without conflicting.
99. What is File Manager?
It is a program module, which manages the allocation of space on disk storage and data
structure used to represent information stored on a disk.
100. What is Authorization and Integrity m anager?
It is the program module, which tests for the satisfaction of integrity constraint and checks
the authority of user to access data.
101. What are stand-alone procedures?
Procedures that are not part of a package are known as stand-alone because they
independently defined. A good example of a stand-alone procedure is one written in a
SQL*Forms application. These types of procedures are not available for reference from other
DBMS LAB MANUAL

P a g e | 105
Oracle tools. Another limitation of stand-alone procedures is that they are compiled at run
time, which slows execution.
102. What are cursors give different types of cursors.
PL/SQL uses cursors for all database information accesses statements. The language supports
the use two types of cursors
Implicit
Explicit
103. What is cold backup and hot backup (in case of Oracle)?
Cold Backup:
It is copying the three sets of files (database files, redo logs, and control file) when the
instance is shut down. This is a straight file copy, usually from the disk directly to tape. You
must shut down the instance to guarantee a consistent copy.
If a cold backup is performed, the only option available in the event of data file loss is
restoring all the files from the latest backup. All work performed on the database since the
last backup is lost.
Hot Backup:
Some sites (such as worldwide airline reservations systems) cannot shut down the database

104. Explain various types of Normal forms?


Sol: There are six normal forms.They are
First Normal Form
Second Normal Form
Third Normal Form
Boyce-Codd Normal Form
Fourth Normal Form
Fifth Normal Form
1 NF No multivalued attributes or repeating groups.
Column values should be atomic, scalar or should be holding single value
No repetition of information or values in multiple columns.

DBMS LAB MANUAL

P a g e | 106

2 NF 1 NF plus no partial dependency


For second normal form our database should already be in first normal form and every nonkey column must depend on entire primary key.

3 NF 2 NF plus no transitive dependencies


It should already be in Second Normal Form.
There should be no transitive dependency, i.e. we shouldnt have any non-key column
depending on any other non-key column.

BCNF-Boyce Codd normal form-Every determinant should be a candidate key.

4NF- A table is in 4NF if and only if, for every one of its non-trivial multivalued dependencies
X Y, X is a super keythat is, X is either a candidate key or a superset thereof.

105. Explain the 4NF? Why it is useful? Explain with example?


Sol: 4NF is concerned with a more general type of dependency known as a multivalued
dependency. A table is in 4NF if and only if, for every one of its non-trivial multivalued
dependencies X Y, X is a super keythat is, X is either a candidate key or a superset
thereof.
Multivalued dependencies
If the column headings in a relational database table are divided into three disjoint groupings
X, Y, and Z, then, in the context of a particular row, we can refer to the data beneath each
group of headings as x, y, and z respectively. A multivalued dependency X Y signifies
that if we choose any x actually occurring in the table (call this choice xc), and compile a list
of all the xcyz combinations that occur in the table, we will find that xc is associated with the
same y entries regardless of z.
A trivial multivalued dependency X Y is one in which Y consists of all columns not
DBMS LAB MANUAL

P a g e | 107
belonging to X. That is, a subset of attributes in a table has a trivial multivalued dependency
on the remaining subset of attributes.
A functional dependency is a special case of multivalued dependency. In a functional
dependency X Y, every x determines exactly one y, never more than one.

106. Explain Atomicity, Consistency, Isolation and Durability?

Sol: Atomicity: Either all operations of the transaction are properly reflected in the database or
none are.
Consistency: Execution of a transaction in isolation preserves the consistency of the database.
Isolation: Although multiple transactions may execute concurrently, each transaction must be
unaware of other concurrently executing transactions. Intermediate transaction results must be
hidden from other concurrently executed transactions. That is, for every pair of transactions Ti
and Tj, it appears to Ti that either Tj, finished execution before Ti started, or Tj started
execution after Ti finished.
Durability: After a transaction completes successfully, the changes it has made to the
database persist, even if there are system failures.

4. Define Transaction? Explain transaction states with neat diagram?


Sol: A transaction is a unit of program execution that accesses and possibly updates various

data

items. To preserve the integrity of data the database system must ensure:
Transaction State
Active the initial state; the transaction stays in this state while it is executing
Partially committed after the final statement has been executed.
Failed --after the discovery that normal execution can no longer proceed.
Aborted after the transaction has been rolled back and the database restored to its state prior
to the start of the transaction. Two options after it has been aborted:
restart the transaction; can be done only if no internal logical error
kill the transaction

DBMS LAB MANUAL

P a g e | 108
Committed after successful completion

5. Discuss about Conflict Serializability?


Sol: Conflict Serializability:Two schedules are conflict equivalent if:
_ Involve the same actions of the same transactions
_ Every pair of conflicting actions is ordered the same way

6.Discuss about View serializability?


Sol: View Serializability:
Let S and S be two schedules with the same set of transactions. S and S are view equivalent
if the following three conditions are met:
1. For each data item Q, if transaction Ti reads the initial value of Q in schedule S, then
transaction Ti must, in schedule S, also read the initial value of Q.
2. For each data item Q if transaction Ti executes read(Q) in schedule S, and that value was
produced by transaction Tj (if any), then transaction Ti must in schedule S also read the value
of Q that was produced by transaction Tj .
3. For each data item Q, the transaction (if any) that performs the final write(Q) operation in
schedule S must perform the final write(Q) operation in schedule S.
As can be seen, view equivalence is also based purely on reads and writes alone.
A schedule S is view serializable it is view equivalent to a serial schedule.
Every conflict serializable schedule is also view serializable.

7. Explain following terms?

A. Dense Index:
Dense indexIndex record appears for every search-key value in the file.

DBMS LAB MANUAL

P a g e | 109
B. Sparse Index:
Sparse Index: contains index records for only some search-key values.
Applicable when records are sequentially ordered on search-key
To locate a record with search-key value Kwe:
Find index record with largest search-key value < K
Search file sequentially starting at the record to which the index record points
C. Primary Index
Primary index: in a sequentially ordered file, the index whose search key specifies the
sequential order of the file.
The search key of a primary index is usually but not necessarily the primary key.
D. Clustered and non clustered:
Clustering index: in a sequentially ordered file, the index whose search key specifies the
sequential order of the file. Also called Primary index
Non-clustering index: an index whose search key specifies an order different from the
sequential order of the file. Also called Secondary index.

8. Define following terms?


i) Dead lock?
System is deadlocked if there is a set of transactions such that every transaction in the set is
waiting for another transaction in the set.
ii) Shared Lock?
Shared(S) mode. Data item can only be read. S-lock is requested using lock-S instruction
iii) Shrinking Phase?
Shrinking Phase:
Transaction may release locks and transaction may not obtain locks.

DBMS LAB MANUAL

P a g e | 110
iv) Growing Phase?
Growing Phase:
Transaction may obtain locks and Transaction may not release locks

******************************************************

DBMS LAB MANUAL

You might also like