CBSE IP (065) - SQL PRACTICE SET 2025-26

(a) Shalini, who works as a database designer in the hotel industry, has created a table named Guest to keep track of guest details as shown below:

Table : Guest

GuestIDGuestNameRoomNumberCheckInDateCharges
G101Harish1012025-04-033000
G102Sunita1012025-04-033000
G103Ramesh1022025-05-045000
G104Bhumika1032025-06-023500

Write a suitable SQL query for the following:

+ I. Display last 3 characters of guest name in upper case.
SELECT UPPER(RIGHT(GuestName, 3)) FROM Guest;
+ II. Display the name of the guest along with the day name of check-in date.
SELECT GuestName, DAYNAME(CheckInDate) FROM Guest;
+ III. Display the remainder when charges are divided by 1000.
SELECT MOD(Charges, 1000) FROM Guest;
+ IV. Extract and display three characters, starting from the second character, of each guest name.
SELECT SUBSTR(GuestName, 2, 3) FROM Guest;

(a) Consider the following tables:

Table 1 : TEACHER
TIDTNameExperienceCity
1Kartik5Bhopal
2Shahnaz6Nagpur
3Rajendra7Delhi
4Tanvi4Bhopal
5Alam9Delhi
Table 2 : SUBJECT
SIDSubNameTID
101Physics1
102Chemistry2
103Mathematics3
104Informatics Practices4
105Computer Science5

Write appropriate SQL query for the following:

+ (I) Delete the record of the subject whose TID is equal to 4.
DELETE FROM SUBJECT WHERE TID = 4;
+ (II) Display the names of teachers who have more than 5 years of experience and who stay in Nagpur.
SELECT TName FROM TEACHER WHERE Experience > 5 AND City = 'Nagpur';
+ (III) Display subject names along with their teacher names.
SELECT SubName, TName FROM TEACHER, SUBJECT WHERE TEACHER.TID = SUBJECT.TID;

(b) Consider the following table and write the output of the following SQL Queries:

Table : ORDERS

ORDERIDCUSTOMERNAMETOTALAMOUNTDISCOUNTORDERDATE
101Hemant5000102024-03-01
102Neha700015NULL
103Keshav300052024-01-20
104Sandhya4500NULL2023-12-25

Write the output of the following SQL Queries:

+ I. SELECT CUSTOMERNAME FROM ORDERS WHERE DISCOUNT IS NOT NULL;
Output:
Hemant
Neha
Keshav
+ II. SELECT CUSTOMERNAME, DISCOUNT FROM ORDERS WHERE DISCOUNT BETWEEN 5 AND 10;
Output:
Hemant | 10
Keshav | 5
+ III. SELECT MONTHNAME(ORDERDATE) FROM ORDERS WHERE ORDERDATE IS NOT NULL;
Output:
March
January
December
+ IV. SELECT ORDERID, DAY(ORDERDATE) FROM ORDERS;
Output:
101 | 1
102 | NULL
103 | 20
104 | 25

Consider the table LIBRARY as given below:

Table : LIBRARY

BookIdTitleGenrePrice
101Python BasicsTechnology278
201The Silent PatientFiction340
301Data ScienceTechnology291
401OceansMarine LifeNULL
+ (I) Which attribute(s) can be considered as the Candidate keys(s) ? Justify your answer.
Candidate keys: BookId and Title.
Justification: Both attributes contain unique values for each record and can uniquely identify each row in the table.
+ (II) Write an SQL query to insert a new record with the following values : 501, 'AI for ALL', 'Technology', 589.
INSERT INTO LIBRARY VALUES (501, 'AI for ALL', 'Technology', 589);
+ (III) Write an SQL query to add a new column Author that is a character data type of size 20.
ALTER TABLE LIBRARY ADD Author VARCHAR(20);