0% found this document useful (0 votes)
6 views4 pages

Assignment 6

The document outlines the design of an ER diagram for a car insurance company, detailing entities, attributes, relationships, and constraints. It includes SQL table creation, data population, and advanced queries to extract information from the database. Assumptions about customer-car relationships and accident reporting are also specified to support the design and queries.

Uploaded by

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

Assignment 6

The document outlines the design of an ER diagram for a car insurance company, detailing entities, attributes, relationships, and constraints. It includes SQL table creation, data population, and advanced queries to extract information from the database. Assumptions about customer-car relationships and accident reporting are also specified to support the design and queries.

Uploaded by

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

Assignment-6

i. Design an ER diagram for an application that models a car-insurance company whose customers
own one or more cars each. Analyze the requirements by identifying the entities,attributes,
relationships, keys, constraints etc. Apply extended entity-relationship features
to the design. Defend your design with proper assumptions and justifications. Map the ER
model into a relational model.

Assumptions:

 Each customer owns at least one car.

 Each car can be associated with only one customer at a time.

 Each accident involves only one car.

 Each policy can have one or more coverages.

 Each policy can have one or more payments.

 Each payment is associated with a specific policy.

 The company operates in a single geographic region and currency.

 All customers provide accurate and up-to-date contact information.

 The insurance premiums are calculated based on factors such as the car's model, year, and
the customer's driving history.

 The system assumes no fraudulent activities, such as false accident reports or payment
claims.

ii. Create tables, populate with data and construct queries (advanced) in SQL to extract
information from the car insurance company’s database.

Queries:
1. Find the total number of people who owned cars that were involved in accidents in 2010.
2. Find the number of accidents in which the cars belonging to “XYZ” were involved.
3. Add a new accident to the database; assume any values for required attributes.
4. Delete the model ‘Scorpio belonging to “ABC”.
5. Update the damage amount for the car with license number “AIBPC2010” in the accident
with report number “FIR271” to Rs. 5000.

Solution of sql+ :

CREATE TABLE Customer (


Customer_ID INT PRIMARY KEY,
Name VARCHAR(100),
Address VARCHAR(100),
Phone_Number VARCHAR(20),
Email VARCHAR(100)
);
CREATE TABLE Car (
Registration_Number VARCHAR(20) PRIMARY KEY,
Make VARCHAR(50),
Model VARCHAR(50),
Year INT,
Customer_ID INT,
FOREIGN KEY (Customer_ID) REFERENCES Customer(Customer_ID)
);

CREATE TABLE Accident (


Report_Number VARCHAR(20) PRIMARY KEY,
Date_of_Accident TIMESTAMP,
Description VARCHAR(200),
Damage_Amount DECIMAL(10, 2),
Registration_Number VARCHAR(20),
FOREIGN KEY (Registration_Number) REFERENCES Car(Registration_Number)
);

INSERT INTO Customer VALUES (1, 'Abinav Singh', '123 kolkata WB', '6201041680',
'[email protected]');

INSERT INTO Customer VALUES (2, 'Swaroop Kumar', '456 patna BR', '9867569834',
'[email protected]');

INSERT INTO Customer VALUES(3, 'Sameer Gupta', '789 mahisbathan WB', '9767569466',
'[email protected]');

INSERT INTO Customer VALUES (4, 'Vishal Raj', '23 darbhanga BR', '9856764467',
'[email protected]');

INSERT INTO Customer VALUES (5, 'Ramesh Kumar', '87 nayapatti WB', '9976568777',
'[email protected]');

INSERT INTO Car VALUES ('ABC123', 'Toyota', 'Corolla', 2015, 1);

INSERT INTO Car VALUES ('DEF456', 'Honda', 'Accord', 2018, 2);

INSERT INTO Car VALUES ('GHI789', 'Ford', 'Fusion', 2017, 3);

INSERT INTO Car VALUES ('JKL012', 'Scorpio', 'Malibu', 2019, 4);

INSERT INTO Car VALUES ('MNO345', 'Fortuner', 'Altima', 2016, 5);

INSERT INTO Car VALUES ('JKL013', 'Scorpio', 'ABC', 2019, 4);

INSERT INTO Car VALUES ('AIBPC2010', 'Fortuner', 'Altima', 2016, 5);

INSERT INTO Accident VALUES ('FIR001', TIMESTAMP '2023-05-15 08:00:00', 'Rear-end collision',
2000.00, 'ABC123');
INSERT INTO Accident VALUES ('FIR002', TIMESTAMP '2023-06-20 12:30:00', 'Side-swipe
accident', 3000.00, 'DEF456');
INSERT INTO Accident VALUES ('FIR003', TIMESTAMP '2023-07-10 15:45:00', 'Parking lot collision',
1500.00, 'ABC123');
INSERT INTO Accident VALUES ('FIR004', TIMESTAMP '2023-08-05 10:15:00', 'Fender bender',
1800.00, 'ABC123');
INSERT INTO Accident VALUES ('FIR005', TIMESTAMP '2023-09-08 17:00:00', 'Intersection crash',
2500.00, 'DEF456');
INSERT INTO Accident VALUES ('FIR007', TIMESTAMP '2020-09-08 17:00:00', 'Intersection crash',
2500.00, 'DEF456');
INSERT INTO Accident VALUES ('FIR008', TIMESTAMP '2020-07-10 15:45:00', 'Parking lot collision',
1500.00, 'ABC123');
INSERT INTO Accident VALUES ('FIR271', TIMESTAMP '2020-07-10 15:45:00', 'Parking lot collision',
1500.00, 'AIBPC2010');

SQL queries solutions:


a. Find the total number of people who owned cars that were involved in accidents in 2010.

SELECT COUNT(DISTINCT c.Customer_ID)


FROM Customer c
JOIN Car ca ON c.Customer_ID = ca.Customer_ID
JOIN Accident a ON ca.Registration_Number = a.Registration_Number
WHERE a.Date_of_Accident BETWEEN '01-Jan-2010' AND '31-Dec-2010';

b. Find the number of accidents in which the cars belonging to “XYZ” were involved.

SELECT COUNT(*)
FROM Accident a
JOIN Car ca ON a.Registration_Number = ca.Registration_Number
JOIN Customer c ON ca.Customer_ID = c.Customer_ID
WHERE c.Name = 'Abhinav Singh’;

c. Add a new accident to the database; assume any values for required attributes.

INSERT INTO Accident VALUES ('FIR006', '01-Apr-2024', 'Side-swipe accident', 3000, 'DEF456');

d. Delete the model ‘Scorpio belonging to “ABC”.

DELETE FROM Car


WHERE Make = 'Scorpio' AND Model = 'ABC';
e. Update the damage amount for the car with license number “AIBPC2010” in the accident with
report number “FIR271” to Rs. 5000

UPDATE Accident
SET Damage_Amount = 5000
WHERE Report_Number = 'FIR271' AND Registration_Number = 'AIBPC2010';

You might also like