English

A shop called Wonderful Garments that sells school uniforms maintain a database SCHOOL UNIFORM as shown below. It consisted of two relations - UNIFORM and PRICE.

Advertisements
Advertisements

Question

A shop called Wonderful Garments that sells school uniforms maintain a database SCHOOL UNIFORM as shown below. It consisted of two relations - UNIFORM and PRICE. They made UniformCode as the primary key for UNIFORM relation. Further, they used UniformCode and Size as composite keys for PRICE relation. By analysing the database schema and database state, specify SQL queries to rectify the following anomalies.

UNIFORM
UCode UName UColor
1 Shirt White
2 Pant Grey
3 Skirt Grey
4 Tie Blue
5 Socks Blue
6 Belt Blue
 
PRICE
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
  1. 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.
  2. M/S Wonderful Garments also keeps handkerchiefs of red color, medium size of `100 each. Insert this record in COST table
  3. 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.
  4. 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.
  5. ALTER table to add the constraint that price of an item is always greater than zero.
Code Writing
Advertisements

Solution

a) RENAME TABLE PRICE TO COST;

b) 

INSERT INTO COST 
VALUES (7, 'M', 100)

c)  

ALTER TABLE COST
    ADD FOREIGN KEY (UCode) REFERENCES Uniform(UCode);

d) ALTER TABLE UNIFORM MODIFY UName VARCHAR(20) NOT NULL

e)  

ALTER TABLE COST
ADD CONSTRAINT Cost_Check CHECK (Price > 0);
shaalaa.com
  Is there an error in this question or solution?
Chapter 8: Introduction to Structured Query Language (SQL) - Exercise [Page 174]

APPEARS IN

NCERT Informatics Practices [English] Class 11
Chapter 8 Introduction to Structured Query Language (SQL)
Exercise | Q 10. | Page 174
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×