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.
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.
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
Step 1: Identify that UName must have a value (NOT NULL) for UCode to be assigned
Step 2: Use ALTER TABLE command with MODIFY to add NOT NULL constraint on UName column