SQL 4 marks Questions
SQL 4 marks Questions
1. Consider the following table STOCK. Write SQL commands for the following statements. [4]
Table: STOCK
i. To display details of all Items in the Stock table in ascending order of StockDate.
ii. To display ItemNo and Item name of those items from Stock table whose UnitPrice is more than Rupees 10.
iii. To display the details of those items whose dealer code (Dcode) is 102 or Quantity in Stock (Qty) is more
than 100 from the table Stock.
iv. To display Maximum UnitPrice of items for each dealer individually as per Dcode from the table Stock.
2. Consider the following tables STORE and SUPPLIERS and answer (a) and (b) parts of this question: [4]
Table: STORE
Table: SUPPLIERS
Scode Sname
1 / 40
21 Premium Stationers
23 Soft Plastics
22 Tetra Supply
2 / 40
3. DIVYA 300 CHEMISTRY 62 2
i. To display details of all the items in the Store table in ascending order of LastBuy.
ii. To display ItemNo and Item name of those items from Store table whose Rate is more than 15 Rupees.
iii. To display the details of those items whose Suppliers code (Scode) is 22 or Quantity in Store (Qty) is more
than 110 from the table Store.
iv. To display the Minimum Rate of items for each Supplier individually as per Scode from the table store.
7. Write SQL queries for (a) to (d) based on the tables PASSENGER and FLIGHT given below: [4]
Table: PASSENGER
3 / 40
Table: FLIGHT
a. Write a query to change the fare to 6000 of the flight whose FNO is F104.
b. Write a query to display the total number of MALE and FEMALE PASSENGERS.
c. Write a query to display the NAME, corresponding FARE and F_DATE of all PASSENGERS who have a
flight to START from DELHI.
d. Write a query to delete the records of flights which end at Mumbai.
8. Write SQL queries for (a) to (d) based on the tables CUSTOMER and TRANSACT given below: [4]
Table : CUSTOMER
Table : TRANSACT
a. Write the SQL statements to delete the records from table TRANSACT whose amount is less than 1000.
b. Write a query to display the total AMOUNT of all DEBITs and all CREDITs.
c. Write a query to display the NAME and corresponding AMOUNT of all CUSTOMERs who made a
transaction type (TTYPE) of CREDIT.
d. Write the SQL statement to change the Phone number of customer whose CNO is 1002 to 9988117700 in the
table CUSTOMER.
9. Consider the following tables WORKER and PAYLEVEL and answer the following parts of this question : [4]
Table : WORKER
4 / 40
15 Ameen Ahmed Mechanic P002 21-Aug-2006 13-Mar-1984
Table : PAYLEVEL
i. To display names and drink codes of those drinks that have more than 120 calories.
ii. To display drink codes, names and calories of all drinks, in descending order of calories.
iii. To display names and price of drinks that have price in the range 12 to 18 (both 12 and 18 included).
iv. Increase the price of all drinks in the given table by 10%.
11. Consider the following tables GAMES and PLAYER and answer the following parts of this question : [4]
Table: GAMES
Table : PLAYER
5 / 40
PCode Name GCode
3 Jatin 101
4 Nazneen 103
i. Write a query to change the Basic salary to 10500 of all those teachers from COLLEGE, who joined the
COLLEGE after 01/02/89 and are above the age of 50.
ii. Write a query to display Name, Age and Basic of all those from COLLEGE, who belong to Physics and
Chemistry department only.
iii. Which command will be used to delete a row from table COLLEGE, in which NAME is VIREN?
iv. Insert the following data in the given table COLLEGE
11, ‘Saurav’, 50, ‘Chemistry’, ‘18/05/93’, 12000, ‘M’
v. Identify the attribute best suitable to be declared as a primary key.
13. Give output for following SQL queries as per given table(s) : [4]
Table: SENDER
6 / 40
MU02 H Sinha 12, Newtown Mumbai
Table : RECIPIENT
13, B1 D, Mayur
ND48 ND50 S Tripathi New Delhi
Vihar
TABLE: STREAM
7 / 40
STRCDE STRNAME
1 SCIENCE+COMP
2 SCIENCE+BIO
3 SCIENCE+ECO
4 COMMERCE+MATHS
5 COMMERCE+SOCIO
6 ARTS+MATHS
7 ARTS+SOCIO
i. List the name of all the students, who have taken stream as COMPUTER.
ii. To count the number of female students.
iii. To display the number of students stream wise.
iv. To display all the records in sorted order of name.
v. To display the stream of student whose name is Harish.
16. Give output for following SQL queries as per given table(s) : [4]
Table: DRESS
8 / 40
10019 EVENING GOWN 850 M003 06-JUN-08
Table:: MATERIAL
MCODE TYPE
M001 TERELENE
M002 COTTON
M004 POLYESTER
M003 SILK
Table: PLAYER
3 Jatin 101
4 Nazneen 103
9 / 40
a. What do you understand by primary key and candidate keys?
b. Write SQL commands for the following statements:
i. To display the name of all GAMES with their GCodes.
ii. To display details of those GAMES which are having PrizeMoney more than 7000.
iii. To display the content of the GAMES table in ascending order of Schedule Date.
iv. To display sum of PrizeMoney for each type of GAMES.
c. Give the output of the following SQL queries:
i. SELECT COUNT (DISTINCT Number) FROM GAMES;
ii. SELECT MAX(ScheduleDate), MIN (ScheduleDate) FROM GAMES;
iii. SELECT Name, GameName FROM GAMES G, PLAYER P WHERE (G.Gcode= P.Gcode AND
G.PrizeMoney>10000);
iv. SELECT DISTINCT Gcode FROM PLAYER;
18. Answer the questions (i) to (v) on the basis of the following tables SHOPPE and ACCESSORIES. [4]
TABLE: SHOPPE
Id SName Area
TABLE: ACCESSORIES
No Name Price Id
i. To display Name and Price of all the Accessories in ascending order of their Price.
ii. To display Id and SName of all Shoppe located in Nehru Place.
iii. To display Minimum and Maximum Price of each Name of Accessories.
iv. To display Name, Price of all Accessories and their respective SName, where they are available.
10 / 40
v. To display name of accessories whose price is greater than 1000.
19. Give output for following SQL queries as per given table(s) : [4]
Table: Books
Table: Issued
Book_Id Quantity_Issued
T0001 4
C0001 5
F0001 2
11 / 40
1009 Priya Rai Physics 03/09/1998 26 12
Table: Admin
TABLE: RECIPIENT
12 / 40
ND48 ND50 S Tripathi 13, B1 D, Mayur Vihar New Delhi
13 / 40
111 Bill MEDICINE F 12
TABLE: SALARY
i. Display NAME of all doctors who are in MEDICINE department having more than 10 yrs experience from
the table DOCTOR.
ii. Display the average salary of all doctors working in ENT department using the tables DOCTOR and
SALARY.SALARY = BASIC + ALLOWANCE.
iii. Display the minimum ALLOWANCE of female doctors.
iv. Display the highest consultation fee among all male doctors.
v. To display the detail of doctor who have experience more than 12 years.
25. Consider the following table GARMENT. Write SQL commands for the following statements. [4]
Table: GARMENT
14 / 40
iv. To display FABRIC wise highest and lowest price of GARMENTS from GARMENT table. (Display
FCODE of each GARMENT along with highest and lowest price)
26. i. What possible output(s) are expected to be displayed on screen at the time of execution of the following [4]
code?
import random
S=["Pen","Pencil","Eraser","Bag","Book"]
for i in range (1,2):
f=random.randint(i,3)
s=random.randint(i+1,4)
print(S[f],S[s],sep=":")
Options :
I. Pencil:Book
II. Pencil:Book
Eraser:Bag
III. Pen:Book
Bag:Book
IV. Bag:Eraser
ii. The table Bookshop in MySQL contains the following attributes:
B_code - Integer
B_name - String
Qty - Integer
Price - Integer
Note the following to establish connectivity between Python and MySQL on a 'localhost' :
Username is 'shop'
Password is 'Book'
The table exists in a MySQL database named Bstore.
The code given below updates the records from the table Bookshop in MySQL.
Statement 1 - to form the cursor object.
Statement 2 - to execute the query that updates the Qty to 20 of the records whose B_code is 105 in the table.
Statement 3 - to make the changes permanent in the database.
mydb=mysql.connect(host="localhost",
user="shop",passwd="Book",database="Bstore")
mycursor=__________ # Statement 1
qry= "update Bookshop set Qty=20 where
B_code=105"
___________________ # Statement 2
___________________ # Statement 3
15 / 40
27. Consider the following tables PRODUCT and CLIENT. Write SQL commands for the following statements. [4]
Table: PRODUCT
Table: CLIENT
Table : CUSTOMER
16 / 40
16 K Agarwal Banglore PC01
Table: CUSTOMER
17 / 40
IC899 MUMBAI KOCHI 1 4
TABLE: FARES
i. Display FL_NO and NO_FLIGHT from KANPUR to BENGALURU from the table FLIGHTS.
ii. Arrange the contents of the table FLIGHTS in the ascending order of FL_NO.
iii. Display the FL_NO and fare to be paid for the flights from DELHI to MUMBAI using the tables FLIGHTS
and FARES, where the fare to be paid = FARE + FARE * TAX % 100.
iv. Display the minimum fare INDIAN AIRLINES is offering from the table FARES.
v. To display the detail fares of Indian airlines.
31. Consider the following tables WORKER and PAYLEVEL and answer (a) and (b) parts of this question: [4]
Table: WORKER
Table: PAYLEVEL
18 / 40
iii. To display the content of all the workers table, whose DOB is in between '19- JAN-1984' and '18-JAN-
1987'.
iv. To add a new row with the following: 19, 'DayaKishore', 'Operator', 'P003', '19- Sep-2008', 17-Jul-1984'
b. Give the output of the following SQL queries:
i. SELECT COUNT (PLEVEL), PLEVEL FROM WORKER GROUP BY PLEVEL;
ii. SELECT MAX(DOB), MIN(DOJ) FROM WORKER;
iii. SELECT Name, PAY FROM WORKER W, PAYLEVEL P WHERE W.PLEVEL = P.PLEVEL AND
W.ECODE < 13;
iv. SELECT PLEVEL, PAY+ ALLOWANCE FROM PAYLEVEL WHERE PLEVEL= "P003 ";
32. Consider the following tables ACTIVITY and COACH and answer (a) and (b) parts of this question: [4]
Table: ACTIVITY
Table: COACH
2 Ravinder 1008
3 Janila 1001
4 Naaz 1003
19 / 40
1 Red rose Double Bed 23/02/02 32000 15
i. To show all information about the Sofa from the INTERIORS table.
ii. To list the ITEMNAME, which are priced at more than 10000 from the INTERIORS table.
iii. To list ITEMNAME and TYPE of those items, in which DATEOFSTOCK is before 22/01/02 from the
INTERIORS table in descending order of ITEMNAME.
iv. To insert a new row in the INTERIORS table with the following data
{14, 'Truelndian' , 'Office Table', '25/03/03', 15000, 20}
v. To display the name of item with their price which have discount more than 20.
34. Write SQL commands for the queries (i) to (iv) and output for (v) to (viii) based on a table COMPANY and [4]
CUSTOMER.
COMPANY
CUSTOMER
20 / 40
103 MOHAN KUMAR 30,000 5 111
i. To display those company name which are having price less than 30000.
ii. To display the name of the companies in reverse alphabetical order.
iii. To increase the price by 1000 for those customer whose name starts with S?
iv. To add one more column t_price with decimal(10, 2) to the table customer
v. SELECT COUNT(*), CITY FROM COMPANY GROUP BY CITY
vi. SELECT MIN(PRICE), MAX(PRICE) FROM CUSTOMER WHERE QTY>10
vii. SELECT AVG(QTY) FROM CUSTOMER WHERE NAME LIKE "%r%"
viii. SELECT PRODUCTNAME, CITY, PRICE FROM COMPANY, CUSTOMER WHERE COMPANY. CID =
CUSTOMER.CID AND PRODUCTNAME= "MOBILE"
35. Give output for following SQL queries as per given table : [4]
Table : LAB
21 / 40
Table : COACH
2 Ravinder 1008
3 Janila 1001
4 Naaz 1003
Table: OWNEDBY
Place C OWNER
KERALA KTDC
HIMACHAL HTDC
ORISSA OTDC
22 / 40
i. To display the RCODE and PLACE of all '5 STAR' resorts in the alphabetical order of the place from
table RESORT.
ii. To display the maximum and minimum rent for each type of resort from table RESORT.
iii. To display the details of all resorts which were started after 31-DEC-05 from table RESORT.
iv. Display the OWNER of all '5 STAR' resorts from tables RESORT and OWNEDBY.
b. Give output for the following SQL queries:
i. SELECT MIN(RENT) FROM RESORT WHERE PLACE = KERALA';
ii. SELECT TYPE, START DATE FROM RESORT WHERE TYPE = 2 STAR' ORDERBY STARTDATE;
iii. SELECT PLACE, OWNER FROM OWNEDBY Where PLACE LIKE "%A";
iv. SELECT RCODE, RENT FROM RESORT, OWNEDBY WHERE (RESORT. PLACE = OWNEDBY.
PLACE AND TYPE = '3 STAR );
38. Write SQL queries for (i) to (iv) and find outputs for SQL queries (v) to (viii), which are based on the table. [4]
TABLE: ACCOUNT
TABLE: TRANSACT
23 / 40
39. What do you understand by Candidate Keys in a table? Give a suitable example of Candidate keys from a table [4]
containing some meaningful data.
40. Consider the following tables CABHUB and CUSTOMER. Write SQL commands for the following statements. [4]
Table: CABHUB
Table: CUSTOMER
C1 RISHABH M 15000
C2 AAKASH M 12500
C3 INDIRA F 9750
C4 TUSHAR M 14600
C5 ANKITA F 22000
Table : TRANSACTION
a. To display all information about the CUSTOMERs whose NAME starts with 'A'.
24 / 40
b. To display the NAME and BALANCE of Female CUSTOMERs (with GENDER as 'F') whose
TRANSACTION Date (TDATE) is in the year 2019.
c. To display the total number of CUSTOMERs for each GENDER.
d. To display the CUSTOMER NAME and BALANCE in ascending order of GENDER.
e. To display CUSTOMER NAME and their respective INTEREST for all CUSTOMERs where
INTEREST is calculated as 8% of BALANCE.
42. Give output for following SQL queries as per given table(s) for (i) to (v) and write sql commands for point (vi) [4]
and (vii).
Table: GARMENT
Table: FABRIC
FCODE TYPE
F04 POLYSTER
F02 COTTON
F03 SILK
F01 TERELENE
25 / 40
ItemNo Item Dcode Qty UnitPrice StockDate
Table: DEALERS
Dcode Dname
26 / 40
335 Henry Williams 12 Moore Street Boston
Table: DESIG
27 / 40
93 Pragya Jain 123 32000 29 05-Aug-2006
Table: DEPARTMENT
103 HR P K Singh
Table: COACH
2 Ravinder 1008
3 Janila 1001
4 Naaz 1003
i. To display the names of all activities with their Acodes in descending order.
ii. To display sum of PrizeMoney for the Activities played in each of the Stadium separately.
iii. To display the coach's names and Acodes in ascending order of Acode from the table COACH.
28 / 40
iv. To display the content of all activities for which ScheduleDate is earlier than 01-01-2004 in ascending order
of ParticipantsNum.
47. Give output for following SQL queries as per given table(s) : [4]
Table: PRODUCT
Table : CLIENT
Table: CONSIGNEE
29 / 40
ND08 ND02 P Dhingra 16/J, Moore Enclave New Delhi
30 / 40
108 Lawn Tennis Outdoor 4 25000 19-Mar-2004
text="LearningCS"
L=len(text)
ntext=""
for i in range (0,L):
if text[i].islower():
ntext=ntext+text[i].upper()
elif text [i].isalnum():
ntext=ntext+text[i 1]
else:
ntext=ntext+'&&'
print(ntext)
mydb=mysql.connect(host="localhost",
user="shop",passwd="Book",database="Bstore")
mycursor=___________ # Statement 1
mycursor.execute("_________") # Statement 2
B_Details=__________ # Statement 3
for i in B_Details:
31 / 40
print(i)
53. Give output for following SQL queries as per given table(s) : [4]
Table : Books
Table : Issued
Book_Id Quantity_Issued
F0001 3
T0001 1
C0001 5
TABLE: ISSUED
Book_Id Quantity_Issued
F0001 3
T0001 1
C0001 5
32 / 40
iii. To display the names and price of the books in descending order of their price.
iv. To increase the price of all books of First Publ Publishers by 50.
v. To display the detail of book whose quantity less than 10.
55. Give output for following SQL queries as per given table(s): [4]
Table : CLUB
Table: CUSTOMER
33 / 40
i. To display the names of all the silver colored Cars.
ii. To display the name of the car, make and capacity of cars in descending order of their seating capacity.
iii. To display the highest charges at which a vehicle can be hired from CARDEN.
iv. To display the customer name and the corresponding name of the cars hired by them.
57. Consider the following tables SCHOOL and ADMIN and answer this question: [4]
TABLE: SCHOOL
TABLE: ADMIN
34 / 40
510 C Class Mercedes RED 4 35
Table: CUSTOMER
Table : SALGRADE
35 / 40
10012 INFORMAL SHIRT 1550 F02 06-JUN-08
TABLE: FABRIC
FCODE TYPE
F04 POLYSTER
F02 COTTON
F03 SILK
F01 TERELENE
36 / 40
i. To show all information about the patients of Cardiology Department.
ii. To list the name of female patients, who are in Orthopaedic Department.
iii. To list names of all patients with their date of admission in ascending order.
iv. To display Patient’s Name, Charges, Age for male patients only.
v. To display name of doctor are older than 30 years and charges for consultation fee is more than 500.
62. Give output for following SQL queries as per given table(s): [4]
Table: HOSPITAL
37 / 40
64. Given the following family relation. Write SQL commands for questions (i) to (v) based on the table FAMILY [4]
TABLE: FAMILY
i. Which command will be used to list the names of the employees, who are more than 34 years old sorted by
NAME.
a. SELECT NAME FROM EMPLOYEE WHERE AGE>34 ORDER BY NAME;
b. SELECT * FROM EMPLOYEE WHERE AGE>34 ORDER BY NAME;
c. SELECT NAME FROM EMPLOYEE WHERE AGE>34;
d. SELECT NAME FROM EMPLOYEE AGE>34 ORDER BY NAME;
38 / 40
ii. Write a query to display a report, listing NAME, BASIC, DEPARTMENT and annual salary. Annual salary
equals to BASIC * 12.
iii. Insert the following data in the EMPLOYEE table
11, 'VIJAY', 9300, 'FINANCE', '13/7/98', 35, "M"
iv. Write a query to count the number of employees, who are either working in PERSONNEL or COMPUTER
department.
v. Write the degree and cardinality of the table EMPLOYEE.
66. Write SQL commands for (i) to (v) on the basis of the table SPORTS [4]
TABLE: SPORTS
i. Display the games taken up by the students, whose name starts with 'A'.
ii. Write a query to add a new column named MARKS.
iii. Write a query to assign a value 200 for Marks for all those, who are getting grade ‘B’ or grade 'A' in both
GAME1 and GAME2.
iv. Which command will be used to arrange the whole table in the alphabetical order of NAME?
a. SELECT FROM SPORTS ORDER BY NAME;
b. SELECT * SPORTS ORDER BY NAME;
c. SELECT * FROM SPORTS ORDER NAME;
d. SELECT * FROM SPORTS ORDER BY NAME;
v. Identify the attribute best suitable to be declared as a primary key.
67. Give output for following SQL queries as per given table(s) : [4]
relation Teacher
39 / 40
i. SELECT COUNT (distinct department) FROM TEACHER;
ii. SELECT MAX (Age) FROM TEACHER WHERE Sex = "F";
iii. SELECT AVG(Salary) FROM TEACHER WHERE Dateofjoin< {12/07/96};
iv. SELECT SUM (Salary) FROM TEACHER WHERE Dateofjoin < {12/07/96}
68. Consider the following table EMPLOYEE. Write SQL commands for the following statements. [4]
Table: EMPLOYEE
40 / 40