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.
Attributes and Constraints
Table: UNIFORM
| Attribute | UCode | UName | UColor |
|---|---|---|---|
| Constraints | Primary Key | Not Null | - |
Table: COST
| Attribute | UCode | Size | Price |
|---|---|---|---|
| Constraints | Composite Primary Key | >0 |
Table: UNIFORM
| UCode | UName | UColor |
|---|---|---|
| 1 | Shirt | White |
| 2 | Pant | Grey |
| 3 | Skirt | Grey |
| 4 | Tie | Blue |
| 5 | Socks | Blue |
| 6 | Belt | Blue |
Table: COST
| UCode | Size | Price |
|---|---|---|
| 1 | M | 500 |
| 1 | L | 580 |
| 1 | XL | 620 |
| 2 | M | 810 |
| 2 | L | 890 |
| 2 | XL | 940 |
| 3 | M | 770 |
| 3 | L | 830 |
| 3 | XL | 910 |
| 4 | S | 150 |
| 4 | L | 170 |
| 5 | S | 180 |
| 5 | L | 210 |
| 6 | M | 110 |
| 6 | L | 140 |
| 6 | XL | 160 |
- 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
- 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
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 question tests understanding of primary key, NOT NULL, and CHECK constraints by asking whether specific tuples violate the schema rules defined for the UNIFORM and COST relations.
Understanding Database Constraints
Before we can decide whether a tuple can be inserted, we need to understand what each constraint means and how it restricts the data.
Primary Key ensures that each value (or combination of values, in the case of a composite key) uniquely identifies a row and cannot be NULL. No two rows can have the same primary key value.
NOT NULL means the attribute must have a value in every row; it cannot be left empty.
CHECK constraint (Price > 0) means the Price attribute must contain a value strictly greater than zero.
The UNIFORM table has UCode as its primary key and UName as NOT NULL. The COST table has a composite primary key on (UCode, Size) and a constraint that Price > 0.
(a) Insertions into UNIFORM Relation
(i) (7, Handkerchief, NULL)
This tuple can be inserted.
UCode = 7is unique (not already in the table), satisfying the primary key constraint.UName = 'Handkerchief'is not NULL, satisfying the NOT NULL constraint.UColor = NULLis allowed becauseUColorhas no NOT NULL constraint.
All constraints are satisfied.
(ii) (4, Ribbon, Red)
This tuple cannot be inserted.
UCode = 4already exists in the UNIFORM table (the row for 'Tie').- Primary keys must be unique, so inserting another row with
UCode = 4violates the primary key constraint.
A common mistake is thinking you can update the primary key by inserting a new row with the same key value. Primary keys are immutable identifiers — if you want to change data for UCode = 4, you must use an UPDATE statement, not INSERT.
(iii) (8, NULL, White)
This tuple cannot be inserted.
UCode = 8is unique, which is fine for the primary key.UName = NULLviolates the NOT NULL constraint onUName.
Even though UCode is valid, the NOT NULL constraint on UName prevents this insertion.
(b) Insertions into COST Relation
(i) (7, S, 0)
This tuple cannot be inserted for two reasons:
-
Foreign key violation (implicit): Although not explicitly stated in the schema diagram,
UCodein COST logically referencesUCodein UNIFORM. SinceUCode = 7does not exist in UNIFORM (we established in part (a)(i) that it could be inserted but hasn't been yet), this would violate referential integrity if a foreign key constraint is enforced. -
CHECK constraint violation:
Price = 0violates the constraintPrice > 0. The price must be strictly greater than zero. …
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.