Assignment 6
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:
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+ :
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 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');
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');
UPDATE Accident
SET Damage_Amount = 5000
WHERE Report_Number = 'FIR271' AND Registration_Number = 'AIBPC2010';