SQL PRACTICE PAPER
SQL PRACTICE PAPER
SALE has degree 4 and cardinality 7, what will be the degree and cardinality of the
Cartesian product of BOOK and SALE?
(a) 32,49 (b) 12,49 (c) 12,14 (d) 32,14
12 Which statement is appropriate to change the first name "Madhur" to "Mridul" in the
"FName" column in the 'Student' table?
(a) UPDATE Student SET FName='Mridul' WHERE FName='Madhur' ;
(b) MODIFY Student SET FName='Madhur' INTO FName='Mridul ;
(c) UPDATE Student SET FName='Madhur' INTO FName='Mridul' ;
(d) UPDATE Student SET FName='Madhur' WHERE FName='Mridul' ;
13 In the relational models , cardinality actually refers to --------------
(a) Number of Tuples (b) Number of Constraints
(c) Number of Attributes (d) Number of Tables
14 Ms. Shalini has just created a table named Employee containing columns Ename, 2
Department, Salary with Ename as the primary key. After creating the table, she realized
that she has forgotten to add Empid in the table. Help her in writing SQL command to add
a column Empid of integer type and set it as the primary key column.
15 Meera got confused with DDL and DML commands. Help her to select only DML
command from the given list of command.
UPDATE,DROP TABLE, SELECT, CREATE TABLE, INSERT INTO, DELETE,USE
16 Write the output of the SQL queries (i) to (iii) based on the table RESULT: 3
NAME STIPEND SUBJECT MARKS CLASS
Amal 200 English 38 Third
Uma 450 Mathematics 67 First
Tarun 300 Physics 56 Second
Vijay 550 Chemistry
Beena 450 Computer 90 First
Select avg(Marks) “Class Average ” from Result where Subject=
(i)
‘Physics’;
(ii) Select Name from Result where Stipend<=400 and Class= ‘Third’;
select Name, Class from Result where Name like ‘%A%’ and Subject
(iii)
in (‘Mathematics’, ‘Computer’);
17 Consider the following table FURNITURE given below: 3
FCODE FNAME PRICE TYPE SCODE
1001 Table 4000 W03 105
1002 Chair 2050 W01 103
1003 Sofa 35000 W02 105
1004 Stand W02 101
1005 Cabinet 18000 W03 102
Based on the given table write SQL queries for the following:
(i) Display the name and price of all furniture of type W03 and price >15000 in alphabetical
order of name.
(ii) Display the supplier code (Scode) and number of furniture supplied by each supplier
from the table furniture, only if the number = 1.
(iii) Change the price of items to 0 if it is having the value NULL.
SECTION D
Each question carries 4 marks [2X4=08]
18 Consider Customer and Transaction Tables Given Below:
Table: CUSTOMER
Acc_No Cust_Name Cust_City Cust_phone Balance
1001 Sunitha Delhi 9878956759 10000
1002 Vivek Mumbai 7863874521 14000
1003 Sandhya Delhi 8945248756 13000
Table: TRANSACTION
Trans_ID Acc_No Trans_Type Amount
T001 1001 Credit 2000
T002 1002 Credit 6000
T003 1002 Debit 7000
T004 1003 Credit 8000
Based on the data given above, answer the following questions:
(a) Write a query to display customer’s name along with their transaction details. 1
(b) Write a query to display the customers from Delhi whose Balance amount is more than 1
10000.
(c) Write a query to display the sum of the transaction amount of each Transaction Type. 1
(d) Remove the column Cust_phone from Table Customer. 1
19 (b) Complete the following database connectivity program by writing the missing statements 4
and performing the given query.
import _________ as mysql # statement 1
con=mysql.________(host='localhost',
user='root, passwd='123',
database='student') # statement 2
cursor=con.cursor()
cursor.execute(_______________________) # statement 3
data=cursor.__________ # statement 4
for rec in data:
print(rec)
con.close()
(a) Complete the statement 1 by writing the name of package need to be imported for
database connectivity.
(b) Complete the statement 2 by writing the name of method require to create connection
between Python and MySQL.
(c) Complete the statement 3 by writing the query to display those students record whose
mark is between 50 and 90 from table Student.
(d) Complete the statement 4 to retrieve all records from the result set.
1. Table Student has the columns RNO and SCORE. It has 3 rows in it. Following two SQL statements
were entered that produced the output (AVG(SCORE) as 45 and COUNT(SCORE) as 2
(i) AVG(SCORE)
(ii) COUNT(SCORE)
Data in SCORE column is same in two rows.
What data is present in the SCORE column in the three rows ?
2. Mary, a Database Administrator, needs to display the average pay of workers from those
departments which have more than five employees. She is experiencing a problem while
running the following query: Write the correct query to perform the task.
SELECT DEPT, AVG(SAL) FROM EMP WHERE COUNT(*) > 5
GROUP BY DEPT;
Table: TECH_COURSE
Development
Dept Count
Dermatogy 3
Cardiology 5
Orthopedics 4
Pediatrics 3
word “an”
Satheesh has created table “student” and is working on the records of the table. Now he has forgotten
the name of the database he is currently working in. Help him to write SQL command for that, also to
view the structure of the table he created.
OR
Expand DDL and DML. Identify the DDL and DML commands from the following:
UPDATE , DROP TABLE, SELECT, CREATE TABLE , INSERT INTO, DELETE , USE
11. Mubarak creates a table Items with a set of records to maintain the details of items. After
creation of the table, he has entered data of 5 items in the table.
Table: items