0% found this document useful (0 votes)
99 views7 pages

SQL PRACTICE PAPER

Uploaded by

divyeshv4785
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
99 views7 pages

SQL PRACTICE PAPER

Uploaded by

divyeshv4785
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

11 In MYSQL database, if a table, BOOK has degree 8 and cardinality 7, and another table,

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;

3. Consider the below table.


(i) Identify the errors in the following SQL statement. Rewrite the correct SQL statement.
SELECT Department, Salary FROM Company GROUP BY Department
(ii) Mr Kumar created two tables Admission and Library to store detail of students. When he
is trying to delete a record of student from Admission table he is unable to perform the
same. What may be possible reason? Both the tables contains a common column Reg_No.
4. Write the output of the queries (i) to (iv) based on the table,
TECH_COURSE given below:

Table: TECH_COURSE

CID CNAME FEES STARTDATE TID

C201 Animation and VFX 12000 2022-07-02 101 3

C202 CADD 15000 2021-11-15 NULL

C203 DCA 10000 2020-10-01 102

C204 DDTP 9000 2021-09-15 104

C205 Mobile Application 18000 2022-11-01 101

Development

C206 Digital marketing 16000 2022-07-25 103


(i) SELECT DISTINCT TID FROM TECH_COURSE;
(ii) SELECT TID, COUNT(*), MIN(FEES) FROM TECH_COURSE
GROUP BY TID HAVING COUNT(TID)>1;
(iii) SELECT AVG(FEES) FROM TECH_COURSE WHERE
FEES BETWEEN 15000 AND 17000;
5. Consider the Table “Gym” shown below. Write commands in SQL for (i) to (iii) 3

i) To display the Mname, FeeGiven of all those male members of


the Gym whose age is less than 50 and are monthly type
members of the Gym
ii) To display Mcode, Mname and Age of members who have ‘mi’
anywhere in their names with Age in descending order .
iii) Display the Type, no:of members in each membership type.
6. Assume that there is a table Doctors in the database Hospital.

DNo – integer DName – string Dept – string

Write a function in Python which implement Python MySql


Connectivity reads the records from the table named Doctors and displays the
number of doctors in each dept.

The output should be in the following format

Dept Count
Dermatogy 3
Cardiology 5
Orthopedics 4
Pediatrics 3

Note the following to establish connectivity between Python and


MYSQL:
i. Username is root
ii. Password is tiger
iii. The table exists in a MYSQL database named Hospital
7. Write the outputs of the SQL queries (i) to (iv) based on the relations SCHOOL and ADMIN
given below
SCHOOL
CODE TEACHERNAME SUBJECT DOJ PERIO EXPERI
DS ENCE
1001 UMA SHANKAR ENGLISH 12/03/2000 NULL 10
1009 NANDITA RAI PHYSICS 03/09/1998 26 12
1203 LISA ANAND ENGLISH 09/04/2000 27 5
1045 YASHRAJ MATHS 24/08/2000 24 15
1123 JEEVAN PHYSICS 16/07/1999 28 4
1167 HARISH B CHEMISTRY 19/10/1999 27 5
1215 RAMESH PHYSICS 11/05/1998 22 16
ADMIN

CODE GENDER DESIGNATION


1001 MALE VICE PRINCIPAL
1009 FEMALE COORDINATOR
1203 FEMALE COORDINATOR
1045 MALE HOD
1123 MALE SENIOR TEACHER
1167 MALE SENIOR TEACHER
1215 MALE HOD

a. Display Code, TeacherName, subject and their Designation

b. Display the Subject and Average period of each Subject whose


Average Period is more than 20.

c. Display the Name of the Coordinators whose name contains the

word “an”

d. Display the Code, Name of the Teacher, Experience and DOJ of

those Senior Teachers who joined in the year 1999.

7. The attribute which have properties to be as referential key is known as.


(a) foreign key (b)alternate key
(c) candidate key (d) Both (a) and (c)
8. Which command is used to change some values in existing rows?
a. CHANGE (b) MODIFY
(c) ALTER (d) UPDATE
16. To get counting of the returned rows, you may use ____________________.
(a) cursor.rowcount (b) cursor.count (c) cursor.countrecords() (d) cursor.manyrecords()

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

ItemNo Item Scode Qty Rate LastBuy


2005 Sharpener Classic 23 60 8 31-JUN-09
2003 Balls 22 50 25 01-FEB-10
2002 Gel Pen Premium 21 150 12 24-FEB-10
2006 Gel Pen Classic 21 250 20 11-MAR-09
2001 Eraser Small 22 220 6 19-JAN-09
Based on the data given above answer the following questions:
i.Identify the most appropriate column, which can be considered as Primary key.
ii.If 3 columns are added and 2 rows are deleted from the table , what will be the new degree and
cardinality of the above table?
iii.Write the statements to:
a. Insert the following record into the table as (2024, Point Pen, 20, 11, 350, 15-NOV-2022).
b. Increase the rate of the items by 2% whose name ends with ‘c’.
35i.Differentiate between fetchmany() and fetchall().
ii.Kabir wants to write a program in Python to create a table named Student and insert the following
record in the table in MYSQL database, SCHOOL:
rno(Roll number )- integer
name(Name) – string
DOB (Date of birth) – Date
Fee – float
Note the following to establish connectivity between Python and MySQL:
Username – root
Password – tiger
Host – localhost
The values of fields rno, name, DOB and fee has to be accepted from the user. Help Kabir to write the
program in Python.
OR
i.Write 1 similarity between where and having clause in MySQL.
ii.Write a python program to read the records from the table named items and display only the names of
those items who have price greater than 100:
ItemNo –integer Name – string Price – integer
Note the following to establish connectivity between Python andMYSQL:
Username is root
Password is epic
The table exists in a MYSQL database named store.
Also, display the number of items whose price is >100.

You might also like