Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
35 views6 pages

1lab1 DB

database lab
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views6 pages

1lab1 DB

database lab
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

DATABASE LAB MANUAL

Objectives
Understand the question presented.
Analyze the provided information to identify entities or attributes for an ER
Diagram.
Differentiate between primary keys and foreign keys, and specify which attributes
are
PK or FK.
Determine the relationship between entities that have a clear connection.

Lab Practice:
Entity Relationship Diagram (ERD)
Conceptual Design
Make an ER Diagram for the car company database with the following description
and Use the Online tool (https://drawio.com/) to create it:

Scenario:

A car rental company maintains a fleet of Cars that can be rented by Customers.
Each Customer can rent multiple cars, and each Car can be rented multiple times.
When a Customer rents a Car, the company records the rental date, return date, and
the total cost for the rental.

Step 1: Identify Entities and Attributes

Based on this scenario, we can identify the following entities:

1. Car
Attributes: car_id (Primary Key), make, model, year, license_plate

2. Customer
Attributes: customer_id (Primary Key), name, phone, email

3. Rental
Attributes: rental_id (Primary Key), rental_date, return_date,
total_cost
Foreign Key 1: customer_id (references Customer)
Foreign Key 2: car_id (references Car)
Step 2: Define Relationships Between Entities

1. A Customer can rent multiple Cars (one-to-many relationship between Customer and Rental).
2. A Car can be rented multiple times by different Customers (one-to-many relationship
between Car and Rental).

Since each Rental involves one Customer and one Car, the Rental entity acts as an
intermediary between Customer and Car. This represents a many-to-many
relationship (many customers can rent many cars), but broken into two one-to-many
relationships through the Rental entity.

Step 3: ER Diagram Structure

Here’s how the entities and relationships would be structured:

Entities:

Car

1. car_id (Primary Key)


2. make
3. model
4. year
5. license_plate

Customer

1. customer_id (Primary Key)


2. name
3. phone
4. Email

Rental

1. rental_id (Primary Key)


2. rental_date
3. return_date
4. total_cost
5. Foreign Key 1: customer_id (references Customer)
6. Foreign Key 2: car_id (references Car)
Relationships:

 One-to-many between Customer and Rental.


 One-to-many between Car and Rental.

Visual Representation (ER Diagram):

Car Entity (Rectangle with attributes inside)

1. Primary Key: car_id


2. Other attributes: make, model, year, license_plate

Customer Entity (Rectangle with attributes inside)

1. Primary Key: customer_id


2. Other attributes: name, phone, email

Rental Entity (Rectangle with attributes inside)

1. Primary Key: rental_id


2. Other attributes: rental_date, return_date, total_cost
3. Foreign Keys: customer_id, car_id

Relationships:

1. A diamond between Customer and Rental for "rents".


2. A diamond between Rental and Car for "is rented".
SQL ONLINE COMPILER:
https://www.programiz.com/sql/online-compiler/

Creating three tables :

Create table Car(


car_id int NOt NULL UNIQUE,
make varchar(50),
model varchar(50),
licence varchar(100),
year int,
Primary key (car_id)
);

create table Customer(


customer_id int Not Null unique,
phone int,
name varchar(100),
mail varchar(100),
primary key (customer_id)
);

create table Rental


(
rental_id int,
rental_date Date,
return_date date,
total_cost int,
customer_id int,
car_id int,

PRIMARY KEY (rental_id),


FOREIGN KEY (customer_id) references Customer(customer_id)
FOREIGN KEY (car_id) references Car(car_id)
);

You might also like