06 DBMS
06 DBMS
(a) To store each item name along with its price, what relation should be used?
Decide appropriate attribute names along with their data type. Each item
and its price should be stored only once. What restriction should be used
while defining the relation?
Ans. To store each item name along with its price in the canteen database, we can
create a relation (table) called "Items" with the following attributes:
Items table
Attributes Datatype Constraints
ItemNo Integer Priimary, non-null, Unique
ItemName Varchar Non-null
Price Float Non-null
The restriction that should be used while defining the "Items" relation is to set
the "ItemNo" attribute as the primary key. This ensures that each item number
is unique and that each item and its price are stored only once in the database.
(b) In order to generate bill, we should know the quantity of an item
purchased. Should this information be in a new relation or a part of the
previous relation? If a new relation is required, decide appropriate name
and data type for attributes. Also, identify appropriate primary key and
foreign key so that the following two restrictions are satisfied:
The same bill cannot be generated for different orders.
Ans. Yes, the item sale information should be stored in a separate relation, say
"SaleOrders".
SaleOrders table
Attributes Datatype Constraints
Orderno Integer Primary key, Unique,
Non-null
ItemNo Integer Foreign Key, Non-null
Quantitiy Integer Non-null
Price Float Non-null
With this design, we satisfy both restrictions:
Each order has a unique OrderNo, ensuring that the same bill cannot be
generated for different orders. The foreign key constraint on ItemNo ensures
that bills can only be generated for available items in the canteen.
Bill can be generated only for available items in the canteen.
(c) The school wants to find out how many calories students intake when they
order an item. In which relation should the attribute 'calories' be stored?
Ans. 'Calories' should be stored in the "Items" table because they are directly
associated with specific items.
9. An organisation wants to create a database EMPDEPENDENT to maintain
following details about its employees and their dependent.
EMPLOYEE(AadharNumber, Name, Address, Department, EmployeeID)
DEPENDENT(EmployeeID, DependentName, Relationship)
(a) Name the attributes of EMPLOYEE, which can be used as candidate keys.
Ans. In the EMPLOYEE table, the attributes AadharNumber and EmployeeID can
be used as candidate keys. This means that either AadharNumber or
EmployeeID can uniquely identify each record in the EMPLOYEE table.
(b) The company wants to retrieve details of dependent of a particular
employee. Name the tables and the key which are required to retrieve this
detail.
Ans. The EMPLOYEE and DEPENDENT tables are linked using the EmployeeID
key, which is utilized to retrieve details of dependents associated with a
specific employee.
(c) What is the degree of EMPLOYEE and DEPENDENT relation?
Ans. In the EMPLOYEE relation, there are five attributes, resulting in a degree of 5.
Similarly, the DEPENDENT relation has three attributes, making its degree 3.
10. School uniform is available at M/s Sheetal Private Limited. They have
maintained SCHOOL_UNIFORM Database with two relations viz.
UNIFORM and COST. The following figure shows database schema and its
state.
(a) Can they insert the following tuples to the UNIFORM Relation ? Give
reasons in support of your answer.
(i) 7, Handkerchief, NULL
(ii) 4, Ribbon, Red
(iii) 8, NULL, White
Ans. (i) Tuple (7, Handkerchief, NULL): This tuple can be inserted because
there is no constraint mentioned in the schema that prohibits NULL
values for the UColor attribute.
(ii) Tuple (4, Ribbon, Red): This tuple can be inserted as all attributes have
valid non-null values.
(iii) Tuple (8, NULL, White): This tuple cannot be inserted because UName
attribute cannot be NULL as per the schema constraints.
(b) Can they insert the following tuples to the COST Relation ? Give reasons in
support of your answer.
(i) 7, S, 0
(ii) 9, XL, 100
Ans. (i) Tuple (7, S, 0): This tuple cannot be inserted because the COST Price
attribute must be greater than 0 as per the schema constraints.
(ii) Tuple (9, XL, 100): This tuple can be inserted as all attributes have valid
values and the COST Price is greater than 0.
11. In a multiplex, movies are screened in different auditoriums. One movie can
be shown in more than one auditorium. In order to maintain the record of
movies, the multiplex maintains a relational database consisting of two
relations viz. MOVIE and AUDI respectively as shown below:
Movie(Movie_ID, MovieName, ReleaseDate)
Audi(AudiNo, Movie_ID, Seats, ScreenType, TicketPrice)
(a) Is it correct to assign Movie_ID as the primary key in the MOVIE relation?
If no, then suggest an appropriate primary key.
Ans. Yes, assigning Movie_ID as the primary key in the MOVIE relation is correct
because each movie has a unique Movie_ID.
(b) Is it correct to assign AudiNo as the primary key in the AUDI relation? If
no, then suggest appropriate primary key.
Ans. It is not correct to assign AudiNo as the primary key in the AUDI relation
because an AudiNo can be repeated for different movies screened in different
auditoriums. To uniquely identify each record in the AUDI relation, a
composite primary key consisting of AudiNo and Movie_ID should be used.
(c) Is there any foreign key in any of these relations?
Ans. Yes, there is a foreign key in the AUDI relation. The Movie_ID attribute in the
AUDI relation is a foreign key that references the Movie_ID primary key in
the MOVIE relation.
12. For the Above given database STUDENT-PROJECT, answer the following:
(a) Name primary key of each table.
Ans. Primary key of each table:
STUDENT: Roll No.
PROJECT: ProjectNo.
PROJECT ASSIGNED: Registration_ID.
(b) Find foreign key(s) in table PROJECT-ASSIGNED.
Ans. The ProjectNo column in the PROJECT ASSIGNED table is a foreign key that
references the ProjectNo column in the PROJECT table.
(c) Is there any alternate key in table STUDENT? Give justification for your
answer.
Ans. In the STUDENT table, the Registration_ID column serves as an alternate key
since it uniquely identifies each student.
(d) Can a user assign duplicate value to the field RollNo of STUDENT table?
Justify.
Ans. No, a user cannot assign a duplicate value to the Roll No field of the
STUDENT table because Roll No is the primary key of the table and it must be
unique.
13. For the below given database STUDENT-PROJECT, can we perform the
following operations?
(a) Insert a student record with missing roll number value.
Ans. No. the Roll No attribute in the STUDENT table is marked as primary key and
NOT NULL. Therefore, inserting a student record with a missing Roll No
value would violate the NOT NULL constraint and is not allowed.
(b) Insert a student record with missing registration number value.
Ans. Yes, the registration_ID attribute in the STUDENT table does not have a NOT
NULL constraint specified in the schema. Therefore, it is possible to insert a
student record without registration number value.
(c) Insert a project detail without submission-date.
Ans. Yes, the SubmissionDate attribute in the PROJECT table does not have a NOT
NULL constraint specified in the schema. Therefore, it is possible to insert a
project detail without a SubmissionDate value.
(d) Insert a record with registration ID IP-101-19 and ProjectNo 206 in table
PROJECT-ASSIGNED.
Ans. No, we cannot perform this operation. ProjectNo in PROJECT ASSIGNED
table serves as a foreign key that references the primary key in the PROJECT
table. Since ProjectNo "206" is not present in the PROJECT table, it cannot be
inserted into the PROJECT ASSIGNED table.