Answer Key

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3
At a glance
Powered by AI
The key takeaways from the document are that SQL is used for managing data in databases and some common SQL functions and clauses are discussed

The main types of SQL commands are DDL, DML, DCL which stand for Data Definition Language, Data Manipulation Language, and Data Control Language respectively

The WHERE clause is applied to individual rows whereas the HAVING clause is applied to groups formed after a GROUP BY clause

 VERY SHORT ANSWER QUESTIONS (1 Mark)

 Which of the following is not a built in aggregate function in SQL? (c)


 State true or false: SQL does not permit distinct with count(*) (a)
 We apply the aggregate function to a group of sets of tuples using the
clause. (a)
 Choose the correct option regarding the query
 SELECT branch_name, COUNT(DISTINCTcustomer_name) FROM
depositor, accountWHERE
depositor.account_number=account.account_number (c )
 The aggregation operation adds up all the values of the attribute (d )
 being aggregated must not be present in the group by clause. ( b)
 State true or false: We can rename the resulting attribute after the
aggregation function has been applied ( a)
 Which keyword is used to rename the resulting attribute after the
application of the aggregation function? ( b)
 What values does the count(*) function ignore? (b )
 What is the meaning of “GROUP BY” clause inMysql? (a )
 Which clause is similar to “HAVING” clause in Mysql? (b )
 “COUNT” keyword belongs to which categories in Mysql? (a )
 Which among the following belongs to an “aggregate function”? (a )
 Which of the following belongs to an “aggregate function”? (d )
 Which clause is used with an “aggregate functions”? (a )
 What is the cardinality of the Cartesian product of table?
 number of rows & column
 Write two examples of RDBMS software.
Oracle, MySQL
 Which SQL keyword is used to retrieve only unique values?
used to select the distinct rows.
 Differentiate between Candidate Key and Alternate Key in context of
RDBMS
A Candidate Key is the one that is capable of becoming Primary key i.e., a field
or attribute that has unique value for each row in the relation.
A Candidate Key that is not a Primary key is called an Alternate Key.

 SHORT ANSWER QUESTIONS (2 Marks)


 What is the purpose and use of SQL?
managing data
 Which commands is(are) used to change a tables’ storage characteristics?
ALTER
 Write the output of following MYSQL queries:
SELECTROUND(6.5675,2);
SELECTTRUNCATE(5.3456,2);
SELECTDAYOFMONTH(curdate());
SELECT MID(‘PRE_BOARDCLASSS 12’,4,6);
 (i ) 6.57 (ii) 5.34(iii) Day no of curdate (), Ex. If curdate is 05/12/2017then
 output is 5 (iv) _BOARD
 Mr.Tiwari created two tables with DEPTNO as Primary key in Table1
and Foreign Key in
Table2.While inserting a row in Table2. Mr.Tiwari is not able to enter a
value in the column DEPTNO.
That value is not existing in the Table1.
 What could be the possible reason and solution for it. Also explain the
significance of foreign key in a table.
That value is not existing in the Table1.
 What are the aggregate functions in SQL?
multiple rows are grouped together as input on certain criteria
 Name some aggregate functions used in SQL.
o Sum( ) b. Avg( ) c. Min()
 What is Order by clause in SQL?
sort the data in ascending or descending order

 What is Group By clause in SQL?


used to arrange identical data into groups with
 What are the various types of Commands available in SQL?
DDL , DML , DCL
 What is the ‘Data Type’? What are the main objectives of datatypes?
set of values
 Optimum use of Storage space , Represent all possible values
 What is the difference between a WHERE clause and a HAVING clause
in SQL SELECT statement?
WHERE condition are applicable on individual rows whereas HAVING
conditions are applicable on groups as formed by GROUP BY clause.

 LONG ANSWER QUESTIONS(3/4/6 Marks)

 Consider the table SHOPPE given below. Write command in MySql for
(i) to (vi) and output for (vii) to(viii).
SELECT Item from SHOPPE WHERE Item like “ C%” ORDER BY Price;
SELECT Code , Item, City FROM SHOPPE WHERE Qty between 50 and100;
SELECT Count (distinct Company) FROMSHOPPE;
INSERTINTOSHOPPEVALUES(“110”,“Pizza”,“Domino”,120,”Kolkata”,50.0);
 Consider the following tables item and Customer. Write SQL Commands
for the statement to(iv)and give outputs for SQL queries (v)to(viii).

SELECT * FROM CUSTOMER WHERE City =‘Delhi’;


SELECT * FROMITEM WHERE PRICE BETWEEN 35000 TO 55000;
SELECT CustomerName, City, ItemName,Price FROM
CUSTOMER,ITEM WHERE CUSTOMER.I_ID = ITEM.I_ID;
UPDATEITEM SET Price = Price + 1000 ;
Delhi
Mumbai
Banglore
(vi) Personalcomputer 37000 3
Laptop 57000 2
(vii) MRS REKHA PQR
o MANSH XYZ
o RAJEEV COMP
o YAJNESH PQR
o VIJAY ABC
(viii) Personal computer 3500000
o Laptop 5500000

You might also like