0% found this document useful (0 votes)
2 views

Lab-5# Experiment 6_ DDL Commands in SQL ## __Lab Objective___ This Lab Aims to Equip Students With Practical Skills in Using Data Definition Language (DDL) Commands in SQL. Students Will Learn to Create, Modify, And Delete Tables, Underst

Srs pdf
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Lab-5# Experiment 6_ DDL Commands in SQL ## __Lab Objective___ This Lab Aims to Equip Students With Practical Skills in Using Data Definition Language (DDL) Commands in SQL. Students Will Learn to Create, Modify, And Delete Tables, Underst

Srs pdf
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Experiment 5: Convert the

Entity-Relationship to a Relational Model


(Tables)
Lab Objective:
This lab aims to equip students with practical skills in converting an Entity-Relationship
(E-R) Diagram into a Relational Model. Students will learn how to analyze an E-R diagram
and design an appropriate relational schema.

Prerequisites:
●​ Basic understanding of E-R diagrams and Relational Database Concepts.
●​ Familiarity with Primary Keys, Foreign Keys, and Normalization.
●​ Access to an SQL environment (e.g., MySQL, PostgreSQL, SQL Server).

Scenario: ROADWAY TRAVELS


The ROADWAY TRAVELS system consists of different entities such as Bus, Reservation,
Ticket, Passenger, and Cancellation. The following relational schema maps these entities
into tables:

1. Bus Table
CREATE TABLE Bus (
BusNo INT PRIMARY KEY,
Source VARCHAR(50) NOT NULL,
Destination VARCHAR(50) NOT NULL,
CouchType VARCHAR(20) NOT NULL
);

●​ BusNo is the Primary Key to uniquely identify each bus.


●​ Source and Destination define the bus route.
●​ CouchType specifies the type of seating arrangement.

2. Reservation Table
CREATE TABLE Reservation (
PNR_No INT PRIMARY KEY,
JourneyDate DATE NOT NULL,
ContactNo VARCHAR(15) NOT NULL,
NoOfSeats INT NOT NULL,
BusNo INT NOT NULL,
Address TEXT,
FOREIGN KEY (BusNo) REFERENCES Bus(BusNo)
);

●​ PNR_No is the Primary Key.


●​ BusNo is a Foreign Key, linking reservations to specific buses.

3. Ticket Table
CREATE TABLE Ticket (
TicketNo INT PRIMARY KEY,
JourneyDate DATE NOT NULL,
Age INT NOT NULL,
DepTime TIME NOT NULL,
Sex CHAR(1) NOT NULL,
Source VARCHAR(50) NOT NULL,
Destination VARCHAR(50) NOT NULL,
BusNo INT NOT NULL,
FOREIGN KEY (BusNo) REFERENCES Bus(BusNo)
);

●​ TicketNo is the Primary Key.


●​ BusNo is a Foreign Key, linking tickets to buses.
●​ DepTime records the departure time of the journey.

4. Passenger Table
CREATE TABLE Passenger (
TicketNo INT NOT NULL,
PNR_No INT NOT NULL,
Age INT NOT NULL,
Sex CHAR(1) NOT NULL,
ContactNo VARCHAR(15) NOT NULL,
Name VARCHAR(100) NOT NULL,
PRIMARY KEY (TicketNo, PNR_No),
FOREIGN KEY (TicketNo) REFERENCES Ticket(TicketNo),
FOREIGN KEY (PNR_No) REFERENCES Reservation(PNR_No)
);

●​ Composite Primary Key (TicketNo, PNR_No) ensures a passenger has both ticket
and reservation.
●​ Foreign Keys maintain integrity between Ticket and Reservation tables.

5. Cancellation Table
CREATE TABLE Cancellation (
PNR_No INT NOT NULL,
JourneyDate DATE NOT NULL,
SeatNo INT NOT NULL,
ContactNo VARCHAR(15) NOT NULL,
PRIMARY KEY (PNR_No, SeatNo),
FOREIGN KEY (PNR_No) REFERENCES Reservation(PNR_No)
);

●​ Composite Primary Key (PNR_No, SeatNo) ensures each cancellation entry is


unique.
●​ Foreign Key ensures cancellations reference valid reservations.

E-R Diagram Representation:


Below is an E-R diagram representation of the ROADWAY TRAVELS database:

[Bus] <---- (1:M) ---- [Reservation] ---- (M:1) ----> [Passenger]


| |
| |
(1:M) (1:1)
| |
[Ticket] [Cancellation]

●​ One bus can have multiple reservations.


●​ One reservation can be linked to multiple passengers.
●​ One reservation can have multiple tickets.
●​ A ticket can be cancelled under the Cancellation entity.

Outcome:
Upon completing this lab, students will:
●​ Be proficient in converting an E-R Diagram to a Relational Model.
●​ Understand how to define Primary and Foreign Keys to maintain data integrity.
●​ Be able to create relational tables and implement real-world database models
effectively.

This experiment helps students understand the importance of database design,


relationships, and constraints while implementing relational databases.

You might also like