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: We will create new relation BILL to keep bill details as per the scheme given below-
Attribute | Data type | Constraint |
BillNo | Int | Primary Key |
BillDate | Date | Not Null |
ICode | Int | Foreign Key (Refrences ITEM) |
Rate | Int | Not Null |
QTY_Sold | Int | Not Null |
Total | Int | Not Null |
We will apply Primary key constraint on ICode attribute to store each item and its price only once.
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:
(i) Bill can be generated only for available items in the canteen.
(ii) The same bill cannot be generated for different orders.
Ans: We will create new relation BILL to keep bill details as per the scheme given below-
Attribute | Data type | Constraint |
BillNo | Int | Primary Key |
BillDate | Date | Not Null |
ICode | Int | Foreign Key (Refrences ITEM) |
Rate | Int | Not Null |
QTY_Sold | Int | Not Null |
Total | Int | Not Null |
(i) We will apply Primary key to BillNo attribute to avoid same bill for different order.
(ii) We will make ICode to Foreign key (References ITEM relation) to generate bill for available items.
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: We have use attribute ‘calories’ in both the relations.