This question asked in CBSE Outside Delhi Set, 2012
Consider the following tables CARDEN and CUSTOMER and answer (a), (b) and (c) parts
Question 6 (a)
Illustrate Primary and Alternate Keys in the given tables (CARDEN and CUSTOMER).
- A primary key is an attribute which can uniquely identify the records in a relation/table.
- An alternate key is an attribute which has not been selected as the primary key, but is a candidate key.
In table CARDEN,
- Primary key - Ccode
- Alternate key - CarName
In table CUSTOMER,
- Primary key - Code
- Alternate key - Cname
Question 6 (b)
Write SQL commands for the following statements:
(i) To display the names of all the silver coloured cars.
To display the names of all the silver coloured cars, the WHERE clause followed by the condition ie., Color=’SILVER’ should be used in the query.
QUERY: SELECT CarName FROM CARDEN WHERE Color=’SILVER’;
(ii) To display names of car, make and capacity of cars in descending order of their sitting capacity.
To display names of car, make and capacity of cars in descending order of their sitting capacity, the ORDER BY clause followed by the column name ie., Capacity followed by the keyword DESC should be used.
QUERY: SELECT CarName,Make,Capacity FROM CARDEN ORDER BY Capacity DESC;
Question 6 (c)
Give the output of the following SQL queries:
(i) SELECT COUNT(DISTINCT Make) FROM CARDEN;
The query will display the number of distinct values in the column Make.
(ii) SELECT MAX(Charges), MIN(Charges)FROM CARDEN;
The query will display the largest and smallest value in the column Charges of table CARDEN.