DB Ass 2
DB Ass 2
Database Systems
Q1: Construct an E-R diagram for a car insurance company whose customers own one
or more cars each. Each car has associated with it zero with any number of recorded
accidents. Each insurance policy covers one or more cars and has one or more premium
payments associated with it. Each payment is for a particular period, and has an
associated due date, and the date when the payment was received
Page |2
Instructor Name: Ms. Maria Gul Department: AI- Blue
Student Name: Ibadullah Qureshi Assignment: 02
Registration No: B23F0001AI072
Q2: An E-R diagram can be viewed as a graph.What do the following mean in terms of
the structure of an enterprise schema?
Page |4
Instructor Name: Ms. Maria Gul Department: AI- Blue
Student Name: Ibadullah Qureshi Assignment: 02
Registration No: B23F0001AI072
Q3: Consider a many-to-one relationship R between entity sets Aand B. Suppose the
relation created from R is combined with the relation created from A. In SQL, attributes
participating in a foreign key constraint can be null. Explain how a constraint on total
participation of A in R can be enforced using not null constraints in SQL.
In a many-to-one (M:1) relationship R between entity sets A and B, multiple entities in A are related
to a single entity in B, but each A must be linked to exactly one B. When the relation from R is
combined with A, we must ensure that every entity in A is always associated with a B (total
participation).
To enforce total participation, the foreign key in A referencing B must be NOT NULL. This
prevents any A entity from existing without being linked to B. Additionally, a foreign key constraint
ensures referential integrity, meaning every referenced B must exist in the database.
For Example:
(b) CREATE TABLE B (
);
CREATE TABLE A (
);
Page |5
Instructor Name: Ms. Maria Gul Department: AI- Blue
Student Name: Ibadullah Qureshi Assignment: 02
Registration No: B23F0001AI072
Q4 Design a database for an automobile company to provide to its dealers to assist them
in maintaining customer records and dealer inventory and to assist sales staff in
ordering cars. Each vehicle is identified by a vehicle identification number (VIN). Each
individual vehicle is a particular model of a particular brand offered by the company
(e.g., the XF is a model of the car brand Jaguar of Tata Motors). Each model can be
offered with a variety of options, but an individual car may have only some (or none) of
the available options. The database needs to store information about models, brands,
and options, as well as information about individual dealers, customers, and cars. Your
design should include an E-R diagram, a set of relational schemas, and a list of
constraints, including primary-key and foreign-key constraints.
Relational Schema
Brand Table
Page |6
Instructor Name: Ms. Maria Gul Department: AI- Blue
Student Name: Ibadullah Qureshi Assignment: 02
Registration No: B23F0001AI072
Brand_Name VARCHAR(255) NOT NULL
);
Model Table
);
Option Table
Description TEXT
);
Vehicle Table
Price DECIMAL(10,2),
Color VARCHAR(50),
Year INT,
);
VIN VARCHAR(20),
Option_ID INT,
Page |7
Instructor Name: Ms. Maria Gul Department: AI- Blue
Student Name: Ibadullah Qureshi Assignment: 02
Registration No: B23F0001AI072
FOREIGN KEY (VIN) REFERENCES Vehicle(VIN),
);
Dealer Table
Location TEXT
);
Customer Table
Contact VARCHAR(20)
);
Order Table
Order_Date DATE,
Total_Amount DECIMAL(10,2),
);
Order_ID INT,
VIN VARCHAR(20),
Page |8
Instructor Name: Ms. Maria Gul Department: AI- Blue
Student Name: Ibadullah Qureshi Assignment: 02
Registration No: B23F0001AI072
FOREIGN KEY (VIN) REFERENCES Vehicle(VIN)
);
Constraints
Primary Keys
Brand_ID in Brand
Model_ID in Model
Option_ID in Option
VIN in Vehicle
Dealer_ID in Dealer
Customer_ID in Customer
Order_ID in Order_Details
Foreign Keys
Explanation of Relationships
Model ↔ Option (M:N) → A model has many options, and an option can be in multiple models.
Page |9
Instructor Name: Ms. Maria Gul Department: AI- Blue
Student Name: Ibadullah Qureshi Assignment: 02
Registration No: B23F0001AI072
Dealer ↔ Customer (M:N) → A dealer can serve multiple customers.
Additional Features
You can add inventory tracking by creating a table to store stock levels.
You can include sales staff and track which staff member processes which order.
Q5 Design a database for a world-wide package delivery company (e.g., DHL or FedEX).
The databasemust be able to keep track of customers (who ship items) and customers
(who receive items); some customers may do both. Each package must be identifiable
and trackable, so the database must be able to store the location of the package and its
history of locations. Locations include trucks, planes, airports, and warehouses. Your
design should include an E-R diagram, a set of relational schemas, and a list of
constraints, including primary-key and foreign-key constraints.\
Relational Schema
P a g e | 10
Instructor Name: Ms. Maria Gul Department: AI- Blue
Student Name: Ibadullah Qureshi Assignment: 02
Registration No: B23F0001AI072
Customer Table
Constraints
Primary Keys: Customer_ID, Package_ID, Location_ID, Tracking_ID
Foreign Keys:
o Sender_ID, Receiver_ID → Customer(Customer_ID)
o Package_ID → Tracking_History(Package_ID)
o Location_ID → Tracking_History(Location_ID)
P a g e | 11