0% found this document useful (0 votes)
18 views7 pages

Assignment 7

Uploaded by

yogov87946
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)
18 views7 pages

Assignment 7

Uploaded by

yogov87946
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/ 7

ASSIGNMENT-7

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.
Create tables, populate with data and construct queries (advanced) in SQL to extract
information from the car insurance company’s database.Consider a car-insurance
company whose customers own one or more cars each. Each car has associated with it
zero to any number of recorded accidents.

customer Table:
CREATE TABLE customer(
cid VARCHAR2(6) CHECK(cid LIKE 'C%') PRIMARY KEY,
address VARCHAR2(15) ,
dob DATE
);

DESC customer;

name Table:
CREATE TABLE name(
cid VARCHAR2(6) REFERENCES customer(cid) ON DELETE CASCADE,
fname VARCHAR2(10) NOT NULL,
mname VARCHAR2(7) NOT NULL,
lname VARCHAR2(8) NOT NULL
);
DESC name;

phone Table:
CREATE TABLE phone(
cid VARCHAR2(6) REFERENCES customer(cid) ON DELETE CASCADE,
phone1 NUMBER(10),
phone2 NUMBER(10)
);
DESC phone;
car Table:
CREATE TABLE car(
licenseno VARCHAR2(10) PRIMARY KEY,
model VARCHAR2(10),
cid VARCHAR2(6) REFERENCES customer(cid) ON DELETE CASCADE
);
DESC car;

commercial Table:
CREATE TABLE commercial(
licenseno VARCHAR2(10) PRIMARY KEY,
fuel_type VARCHAR2(10)
);
DESC commercial;

personal Table:
CREATE TABLE personal(
licenseno VARCHAR2(10) PRIMARY KEY,
no_of_seats NUMBER(3)
);
DESC personal;

accident Table:
CREATE TABLE accident(
licenseno VARCHAR2(10) PRIMARY KEY REFERENCES car(licenseno) ON DELETE
CASCADE,
report_no VARCHAR(10) NOT NULL,
acc_date DATE,
damage_amount NUMBER(10)
);
DESC accident;

Enter at least 5 sets of records in each table form created in part


customer:
INSERT INTO customer VALUES('C0001','kolkata','12-10-2002');
INSERT INTO customer VALUES('C0002','mumbai','11-11-2004');
INSERT INTO customer VALUES('C0003','chennai','12-08-2007');
INSERT INTO customer VALUES('C0004','kolkata','01-12-2005');
INSERT INTO customer VALUES('C0005','new delhi','12-10-2004');
SELECT *FROM customer;

name:
INSERT INTO name VALUES('C0001','XYZ','kr','das');
INSERT INTO name VALUES('C0002','ABC','singh','malik');
INSERT INTO name VALUES('C0003','DFG',' ','roy');
INSERT INTO name VALUES('C0004','MNO','kr','ghosh');
INSERT INTO name VALUES('C0005','ALO',' ','datta');
SELECT *FROM name;

phone:
INSERT INTO phone VALUES('C0001', 9876543210, 9123456789);
INSERT INTO phone VALUES('C0002', 9823456789, 9123451234);
INSERT INTO phone VALUES('C0003', 9812345678, NULL);
INSERT INTO phone VALUES('C0004', 9712345678, 9812341111);
INSERT INTO phone VALUES('C0005', 9998765432, NULL);
SELECT *FROM phone;

car:
INSERT INTO car VALUES('WB01A1000', 'Maruti', 'C0001');
INSERT INTO car VALUES('MH01B2000', 'Scorpio', 'C0002');
INSERT INTO car VALUES('TN01C3000', 'Hyundai', 'C0003');
INSERT INTO car VALUES('WB02D4000', 'Ford', 'C0004');
INSERT INTO car VALUES('DL01E5000', 'Honda', 'C0005');
SELECT *FROM car;

commercial:
INSERT INTO commercial VALUES('WB01A1000', 'Diesel');
INSERT INTO commercial VALUES('MH01B2000', 'Petrol');
INSERT INTO commercial VALUES('TN01C3000', 'Petrol');
INSERT INTO commercial VALUES('WB02D4000', 'Diesel');
INSERT INTO commercial VALUES('DL01E5000', 'CNG');
SELECT *FROM commercial;

personal:
INSERT INTO personal VALUES('WB01A1000', 5);
INSERT INTO personal VALUES('MH01B2000', 7);
INSERT INTO personal VALUES('TN01C3000', 4);
INSERT INTO personal VALUES('WB02D4000', 5);
INSERT INTO personal VALUES('DL01E5000', 4);
SELECT *FROM personal;
accident:
INSERT INTO accident VALUES('WB01A1000', 'FIR123', '10-05-2010', 2000);
INSERT INTO accident VALUES('MH01B2000', 'FIR124', '12-07-2012', 1500);
INSERT INTO accident VALUES('TN01C3000', 'FIR125', '10-08-2015', 3000);
INSERT INTO accident VALUES('WB02D4000', 'FIR271', '01-01-2010', 2500);
INSERT INTO accident VALUES('DL01E5000', 'FIR127', '12-12-2019', 4000);
SELECT *FROM accident;

Write and run the following SQL queries for your database:
1. Find the total number of people who owned cars that were involved in accidents in 2010.
Query:
SELECT COUNT(DISTINCT cid) AS total_owners FROM car WHERE licenseno IN (SELECT licenseno
FROM accident WHERE EXTRACT(YEAR FROM acc_date) = 2010);

2. Find the number of accidents in which the cars belonging to “XYZ” were involved.
Query:
SELECT COUNT(*) AS accident_count FROM accident WHERE licenseno IN (SELECT licenseno
FROM car WHERE cid IN (SELECT cid FROM name WHERE fname = 'XYZ' ));

3. Add a new accident to the database; assume any values for required attributes.
Query:
INSERT INTO car VALUES('DL01E5001', 'Suzuki', 'C0004');
INSERT INTO accident VALUES('DL01E5001', 'FIR128', '15-09-2024', 10000);
SELECT *FROM accident;
4. Delete the model ‘Scorpio' belonging to “ABC”.
Query:
DELETE FROM car WHERE licenseno IN (SELECT licenseno FROM car WHERE model = 'Scorpio'
AND cid IN (SELECT cid FROM name WHERE fname = 'ABC' ));
SELECT *FROM car;

5. Update the damage amount for the car with license number “WB01A1000” in the accident with
report number “FIR271” to Rs. 5000.
Query:
UPDATE accident SET damage_amount = 5000 WHERE licenseno = 'WB02D4000' AND report_no =
'FIR271';
SELECT *FROM accident;

You might also like