They made UniformCode as the primary key for UNIFORM relation. Further, they used UniformCode and Size as composite keys for PRICE relation. By analyzing the database schema and database state, specify SQL queries to rectify the following anomalies.
(a) The PRICE relation has an attribute named Price. In order to avoid confusion, write SQL query to change the name of the relation PRICE to COST.
ALTER TABLE PRICE RENAME TO COST;
(b) M/S Wonderful Garments also keeps handkerchiefs of red color, medium size of 100 each. Insert this record in COST table.
INSERT INTO UNIFORM VALUES (7, ‘Handkerchief’, ‘Red’)
INSERT INTO COST VALUES (7, ‘M’, 100);
(c) When you used the above query to insert data, you were able to enter the values for handkerchief without entering its details in the UNIFORM relation. Make a provision so that the data can be entered in COST table only if it is already there in UNIFROM table.
ALTER TABLE COST ADD FOREIGN KEY (UCode) REFERENCES UNIFORM (UCode);
(d) Further, you should be able to assign a new UCode to an item only if it has a valid Uname. Write a query to add appropriate constraint to the SCHOOL_ UNIFORM database.
ALTER TABLE UNIFORM ADD UNIQUE (UName);
(e) ALTER table to add the constraint that price of an item is always greater than zero.
ALTER TABLE COST ADD CHECK (Price >100);