Skip to content
Exercises · Q8

Q.The school canteen wants to maintain records of items available in the school canteen and generate bills when students purchase any item from the canteen. The school wants to create a canteen database to keep track of items in the canteen and the items purchased by students. Design a database by answering the following questions:

(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?
(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) The same bill cannot be generated for different orders.
ii) 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?
Tripura TbseTextbookSubjective· 4mImportance★★★★★
31% · 9/29 Questions
🔒 Locked · start free trial →

You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.

Start your 14-day free trial to unlock the full solution →

This is a database design problem. The solution uses two relations: Item (item details stored once) and Bill (purchase records linked via foreign key). Calories belong in the Item relation.

This question tests your understanding of database normalization — the idea that you should store each fact in exactly one place to avoid redundancy and update anomalies. The canteen scenario is a classic one-to-many relationship: one item can appear in many bills, but each bill line refers to exactly one item.

Let's break it down part by part.


(a) To store each item name along with its price, you need a relation that captures the item master data. Since each item and its price should be stored only once, this is a single table with a unique identifier for each item.

Relation name: Item

Attributes and data types:

  • item_id — INT (or INTEGER), primary key. This uniquely identifies each item.
  • item_name — VARCHAR(100) (or TEXT). Stores the name of the item.
  • price — DECIMAL(10,2) (or FLOAT/NUMERIC). Stores the price in rupees with two decimal places.

Restriction: The primary key constraint on item_id ensures each item is stored only once. Additionally, you could add a UNIQUE constraint on item_name if item names are also unique, but the question only requires that each item and its price be stored once — the primary key achieves that.

Watch out

Do not store price in a separate table without linking it to the item — that would break the "stored only once" rule and create redundancy.


(b) The quantity of an item purchased is transactional data — it changes with every purchase. This should not be in the Item relation because that would force you to update the item's row every time someone buys it, which is messy and loses history. Instead, create a new relation for the bill/purchase details.

Relation name: Bill

Attributes and data types:

  • bill_no — INT, primary key. Uniquely identifies each bill.
  • item_id — INT, foreign key referencing Item(item_id). Links the purchase to a specific item.
  • quantity — INT (or SMALLINT). Stores how many units of that item were purchased.
  • purchase_date — DATE (optional but practical). Not required by the question, but good practice.

Primary key: bill_no — this satisfies restriction (i): the same bill number cannot appear twice, so different orders get different bill numbers.

Foreign key: item_id references Item(item_id) — this satisfies restriction (ii): a bill can only be generated for an item that exists in the Item table. The database will reject any attempt to insert a bill with an item_id that is not present in Item. …

Unlock everything free for 14 days

  • Full step-by-step solutions
  • Concept-first explanations
  • Methods, shortcuts & mistakes
  • PYQ mapping + timed mock tests

Full access for 14 days. No credit card required.