Question 26 of 32advanced🔧 ApplyShort Answer2 marks

Further, they should be able to assign a new UCode to an item only if it has a valid UName. Write a query to add appropriate constraints to the SCHOOLUNIFORM database.

Correct Answer

To ensure that a new UCode can be assigned to an item only if it has a valid UName, we need to add a NOT NULL constraint on the UName attribute of the UNIFORM table. This will prevent insertion of records where UName is missing or invalid.

The SQL query to add this constraint is: sql ALTER TABLE UNIFORM MODIFY UName VARCHAR(20) NOT NULL;

This constraint ensures that every tuple in the UNIFORM table must have a valid (non-null) UName value. Without a valid UName, the database will not allow the assignment of a UCode to any item, thereby maintaining data integrity in the SCHOOLUNIFORM database.

Exercise: EXERCISE | Q: 6(c) | (Page 49)
For More Understanding

Explanation

The question requires adding a constraint to ensure UName is valid before UCode can be assigned. This is achieved by adding a NOT NULL constraint on UName column in the UNIFORM table. The ALTER TABLE command with MODIFY clause is used to add this constraint to an existing table. This prevents any record from being inserted without a valid UName value.

Solution Steps

  1. Step 1: Identify that UName must have a value (NOT NULL) for UCode to be assigned

  2. Step 2: Use ALTER TABLE command with MODIFY to add NOT NULL constraint on UName column