Chapter 9 Structured Query Language (SQL)
Chapter 9 Structured Query Language (SQL)
4. Which of the following is a correct SQL statement to create a database named Library?
a) MAKE DATABASE Library;
b) NEW DATABASE Library;
c) CREATE DATABASE Library;
d) DATABASE Library;
Answer: c
5. Which command is used to list all databases in MySQL?
a) LIST DATABASES;
b) SHOW ALL DATABASES;
c) DISPLAY DATABASES;
d) SHOW DATABASES;
Answer: d
b) Delete a database
c) Select a database for use
d) Exit SQL
Answer: c
7. Which of the following is a valid datatype for storing dates in MySQL?
a) DATE
b) DATETIME
c) TIME
d) All of the above
Answer: d
b) DELETE
c) DROP
d) ALTER
Answer: c
13. Which command is used to view the structure of a table?
a) SHOW tablename
b) DESCRIBE tablename
c) VIEW tablename
d) PRINT tablename
Answer: b
15. What happens if you run an UPDATE statement without a WHERE clause?
a) Nothing happens
b) Syntax error
c) All records are updated
d) Only the first record is updated
Answer: c
16. Which statement is used to insert data into a table?
a) ADD INTO
b) INSERT INTO
c) PUT INTO
d) ENTER INTO
Answer: b
17. In which format is the DATE stored in MySQL?
a) DD-MM-YYYY
b) MM-DD-YYYY
c) YYYY-MM-DD
d) Any format
Answer: c
b) LIKE
c) BETWEEN
d) ALL
Answer: a
19. Which SQL function returns the remainder of a division operation?
a) DIV
b) REM
c) MOD
d) ROUND
Answer: c
24. Which clause helps in fetching only unique values from a column?
a) ONLY
CHAPTER 9 STRUCTURED QUERY LANGUAGE (SQL) II PUC
b) UNIQUE
c) DISTINCT
d) NON-REPEATED
Answer: c
25. What is the result of any arithmetic operation with NULL?
a) 0
b) NULL
c) Error
d) Infinity
Answer: b
b) UCASE()
c) TOUPPER()
d) CAP()
Answer: b
31. Which clause is used to group rows that have the same values?
a) ORDER BY
b) GROUP BY
c) SET BY
d) UNION
Answer: b
36. Which clause in SQL is used to group records that have the same values in specified columns?
a) ORDER BY
CHAPTER 9 STRUCTURED QUERY LANGUAGE (SQL) II PUC
b) GROUP BY
c) WHERE
d) HAVING
Answer: b
37. Which operator is used to test for NULL values?
a) = NULL
b) == NULL
c) IS NULL
d) EQUAL NULL
Answer: c
b) 3
c) 1
d) 0
Answer: a
43. What is the purpose of the DEFAULT constraint?
a) Allows duplicate values
b) Adds a default value when no input is given
c) Restricts NULL values
d) Sets a foreign key
Answer: b
47. Which of the following is a valid constraint that can be applied to enforce referential integrity
between two tables?
a) DEFAULT
b) PRIMARY KEY
c) UNIQUE
d) FOREIGN KEY
Answer: d
48. Which of the following conditions must be satisfied for a FOREIGN KEY to be added to a
CHAPTER 9 STRUCTURED QUERY LANGUAGE (SQL) II PUC
table?
a) The table must have a DATE column
b) The referenced attribute must be of FLOAT type
c) The referenced column must be a PRIMARY KEY
d) The referenced table must be empty
Answer: c
49. Which SQL operator is used to check whether a column value falls between two values (inclu-
sive)?
a) IN
b) LIKE
c) RANGE
d) BETWEEN
Answer: d
51. Assertion (A): SQL is used only for retrieving data from databases. Reason (R): SQL stands
for Structured Query Language.
a) Both A and R are true, and R is the correct explanation of A
b) Both A and R are true, but R is not the correct explanation of A
c) A is false, but R is true
d) A is true, but R is false
Answer: c
52. Assertion (A): VARCHAR stores variable-length character strings. Reason (R): CHAR and
VARCHAR allocate the same amount of memory for any string.
a) Both A and R are true, and R is the correct explanation of A
b) Both A and R are true, but R is not the correct explanation of A
c) A is true, but R is false
d) A is false, but R is true
Answer: c
53. Assertion (A): PRIMARY KEY allows duplicate values in a column. Reason (R): PRIMARY
KEY is used to uniquely identify each record.
a) Both A and R are true, and R is the correct explanation of A
CHAPTER 9 STRUCTURED QUERY LANGUAGE (SQL) II PUC
54. Assertion (A): ALTER TABLE statement can be used to add a new column. Reason (R): ALTER
TABLE can modify the structure of an existing table.
a) Both A and R are true, and R is the correct explanation of A
b) Both A and R are true, but R is not the correct explanation of A
c) A is false, but R is true
d) A is true, but R is false
Answer: a
55. Assertion (A): The keyword DESC is used to sort records in descending order. Reason (R): The
ORDER BY clause displays records in random order by default.
a) Both A and R are true, and R is the correct explanation of A
b) Both A and R are true, but R is not the correct explanation of A
c) A is true, but R is false
d) A is false, but R is true
Answer: c
56. Assertion (A): SQL is a case-insensitive language. Reason (R): In SQL, ‘salary’ and ‘SALARY’
are treated as the same column names.
a) Both A and R are true, and R is the correct explanation of A
b) Both A and R are true, but R is not the correct explanation of A
c) A is false, but R is true
d) A is true, but R is false
Answer: a
57. Assertion (A): The CREATE TABLE command is used to define the structure of a new table.
Reason (R): CREATE TABLE can define attribute names, data types, and constraints.
a) Both A and R are true, and R is the correct explanation of A
b) Both A and R are true, but R is not the correct explanation of A
c) A is true, but R is false
d) A is false, but R is true
Answer: a
58. Assertion (A): DEFAULT constraint ensures that every column must have a unique value.
Reason (R): DEFAULT sets a predefined value for a column when no value is provided.
a) Both A and R are true, and R is the correct explanation of A
b) Both A and R are true, but R is not the correct explanation of A
CHAPTER 9 STRUCTURED QUERY LANGUAGE (SQL) II PUC
59. Assertion (A): DELETE statement removes a table from the database. Reason (R): DROP
TABLE statement is used to remove a table permanently.
a) Both A and R are true, and R is the correct explanation of A
b) Both A and R are true, but R is not the correct explanation of A
c) A is false, but R is true
d) A is true, but R is false
Answer: c
60. Assertion (A): The WHERE clause in SQL is used to filter groups formed by GROUP BY.
Reason (R): HAVING clause filters records before they are grouped.
a) Both A and R are true, and R is the correct explanation of A
b) Both A and R are true, but R is not the correct explanation of A
c) A is false, but R is true
d) Both A and R are false
Answer: d
61. Assertion (A): INSERT INTO command adds new records into a table. Reason (R): Records
can be inserted without specifying column names if all values are provided in correct order.
a) Both A and R are true, and R is the correct explanation of A
b) Both A and R are true, but R is not the correct explanation of A
c) A is true, but R is false
d) A is false, but R is true
Answer: a
62. Assertion (A): A FOREIGN KEY can reference a column that is not a primary key. Reason
(R): A foreign key ensures that each value exists in another table’s primary key column.
a) Both A and R are true, and R is the correct explanation of A
b) A is true, but R is false
c) A is false, but R is true
d) Both A and R are false
Answer: c
63. Assertion (A): ROUND() is used to round numbers to specified decimal places. Reason (R):
ROUND(283.2, 0) will return 283.2.
a) Both A and R are true, and R is the correct explanation of A
b) Both A and R are true, but R is not the correct explanation of A
c) A is true, but R is false
CHAPTER 9 STRUCTURED QUERY LANGUAGE (SQL) II PUC
64. Assertion (A): The % symbol in SQL is used to match zero or more characters. Reason (R):
The LIKE clause in SQL supports pattern matching using wildcards.
a) Both A and R are true, and R is the correct explanation of A
b) Both A and R are true, but R is not the correct explanation of A
c) A is true, but R is false
d) A is false, but R is true
Answer: a
65. Assertion (A): The BETWEEN operator is inclusive of boundary values. Reason (R): BE-
TWEEN is used to test if a value lies between a specified range.
a) Both A and R are true, and R is the correct explanation of A
b) Both A and R are true, but R is not the correct explanation of A
c) A is true, but R is false
d) A is false, but R is true
Answer: a
66. Assertion (A): You can use the alias keyword AS to rename a column in the output. Reason
(R): Column aliasing affects the actual table structure permanently.
a) Both A and R are true, and R is the correct explanation of A
b) Both A and R are true, but R is not the correct explanation of A
c) A is true, but R is false
d) A is false, but R is true
Answer: c
67. Assertion (A): NOW() function returns the current system date and time. Reason (R): NOW()
is a date function used in MySQL.
a) Both A and R are true, and R is the correct explanation of A
b) Both A and R are true, but R is not the correct explanation of A
c) A is false, but R is true
d) A is true, but R is false
Answer: a
68. Assertion (A): MID() function is used to extract a part of a string. Reason (R): MID() is a
numeric function used to perform arithmetic operations.
a) Both A and R are true, and R is the correct explanation of A
b) Both A and R are true, but R is not the correct explanation of A
c) A is true, but R is false
d) A is false, but R is true
CHAPTER 9 STRUCTURED QUERY LANGUAGE (SQL) II PUC
Answer: c
69. Assertion (A): The TRIM() function is used to remove trailing spaces only. Reason (R): TRIM()
removes both leading and trailing spaces from a string.
a) Both A and R are true, and R is the correct explanation of A
b) Both A and R are true, but R is not the correct explanation of A
c) A is true, but R is false
d) A is false, but R is true
Answer: d
70. Assertion (A): The IS NULL operator is used to check for zero values. Reason (R): IS NULL
checks whether a column has NULL as its value.
a) Both A and R are true, and R is the correct explanation of A
b) Both A and R are true, but R is not the correct explanation of A
c) A is false, but R is true
d) A is true, but R is false
Answer: c
9. To display all columns from a table, we use the symbol in a SELECT statement.
Answer: *
14. To define a column with fixed length string data, we use the datatype .
Answer: CHAR
15. The datatype stores numeric values with decimal points.
Answer: FLOAT
18. The constraint automatically fills in a column with a predefined value when no
input is given.
Answer: DEFAULT
19. To rename a column in the output of a SELECT query, we use the keyword .
Answer: AS
20. The operator is used to check if a column value is within a set of values.
Answer: IN
21. The function returns the number of characters in a string.
Answer: LENGTH()
22. The function removes both leading and trailing spaces from a string.
Answer: TRIM()
25. The clause is used with SELECT to retrieve only unique values.
Answer: DISTINCT
27. The operator is used to retrieve records where a column value lies within a specific
range.
Answer: BETWEEN
29. A column that refers to a primary key in another table is called a key.
Answer: foreign
30. The command permanently removes all records from a table and the table structure
itself.
Answer: DROP
2 MARKS QUESTIONS
1. What is SQL?
Answer: SQL stands for Structured Query Language. It is a language used to create, manipulate, and
retrieve data from relational databases like MySQL, Oracle, SQL Server, etc.
11. How do you add a new column to an existing table? Give syntax and example.
Answer:
Syntax: ALTER TABLE tablename ADD column_name datatype;
Example:
ALTER TABLE GUARDIAN ADD Income INT;
13. Write the syntax to insert data into a table and give an example.
Answer:
Syntax: INSERT INTO tablename VALUES (value1, value2, ...);
Example:
INSERT INTO STUDENT VALUES (1, 'Atharv Ahuja', '2003-05-15', 444444444444);
14. What is the use of the SELECT statement? Give a simple example.
Answer: SELECT is used to retrieve data from a table.
Example:
SELECT * FROM STUDENT;
15. What is the purpose of the DISTINCT clause in a SELECT query?
Answer: DISTINCT is used to return only unique (non-duplicate) values in the output of a SELECT
statement.
16. Give the syntax of the ORDER BY clause and state its default order.
Answer:
Syntax: SELECT * FROM tablename ORDER BY column_name [ASC|DESC];
Default order is ascending (ASC).
18. Write a query to display employee names and their annual income (Salary * 12), using column
aliases.
Answer:
3 MARKS QUESTIONS
2. Differentiate between DDL and DML commands with one example each.
Answer:
DDL (Data Definition Language) defines the structure of a database. Example: CREATE TABLE.
DML (Data Manipulation Language) is used to manage data in tables. Example: INSERT INTO.
3. Write the syntax of the CREATE TABLE command and give an example to create a STUDENT
table with RollNumber, Name, and DateOfBirth.
Answer:
Syntax:
Example:
5. What is a foreign key? Give its syntax and explain with an example.
Answer:
A foreign key is a column that refers to the primary key of another table.
Syntax:
Example:
6. Write a query to insert a record into the GUARDIAN table. Also, write a query to add a new
column Occupation.
Answer:
Insert:
CHAPTER 9 STRUCTURED QUERY LANGUAGE (SQL) II PUC
INSERT INTO GUARDIAN VALUES (444444444444, 'Prithvi Raj', 'M', 'Doctor', 1200000);
Add column:
7. Write a query to update the salary of employee code 103 to 80000 and delete employee with code
104.
Answer:
Update:
Delete:
8. What is the difference between DELETE and DROP commands? Give one use case each.
Answer:
DELETE removes specific rows but retains the table structure.
Example: DELETE FROM STUDENT WHERE RollNumber = 1;
DROP removes the table structure entirely.
Example: DROP TABLE STUDENT;
9. Explain the use of SELECT statement with WHERE and ORDER BY clauses using an example.
Answer:
SELECT retrieves records from a table.
WHERE filters rows based on a condition.
ORDER BY sorts the results.
Example:
10. Write a query using DISTINCT to display unique city names from the CUSTOMER table.
Also, explain its use.
Answer:
Query:
Explanation: DISTINCT is used to remove duplicate values from the result set.
11. Differentiate between the WHERE and HAVING clauses with example queries.
Answer:
WHERE filters rows before grouping;
CHAPTER 9 STRUCTURED QUERY LANGUAGE (SQL) II PUC
12. Write queries to demonstrate the use of LIKE operator with the patterns:
a) Names starting with ‘A’
b) Names ending with ‘n’
c) Names containing ‘sh’
Answer:
a) SELECT * FROM EMPLOYEE WHERE Ename LIKE 'A%';
b) SELECT * FROM EMPLOYEE WHERE Ename LIKE '%n';
c) SELECT * FROM EMPLOYEE WHERE Ename LIKE '%sh%';
13. What are wildcard characters in SQL? Explain % and _ with suitable examples.
Answer:
Wildcards are used with LIKE for pattern matching.
% – Matches zero or more characters.
Example: 'K%' matches ‘Kiran’, ‘Kunal’
_ – Matches exactly one character.
Example: 'K_nal' matches ‘Kunal’, not ‘Kiran’
14. Write SQL queries to:
a) Display all records from SALE where SAmount is greater than 200000
b) Display all records between SAmount 150000 and 250000
Answer:
a) SELECT * FROM SALE WHERE SAmount > 200000;
b) SELECT * FROM SALE WHERE SAmount BETWEEN 150000 AND 250000;
15. List any three aggregate functions in SQL with their purpose.
Answer:
1. SUM() – Returns total sum of values.
2. AVG() – Returns average of values.
3. COUNT() – Returns number of records.
16. Write a query using GROUP BY to count the number of employees in each department.
Answer:
17. Explain the use of MOD() and ROUND() functions with examples.
Answer:
CHAPTER 9 STRUCTURED QUERY LANGUAGE (SQL) II PUC
SELECT NOW();
19. Write the difference between single-row functions and aggregate functions. Give two examples
of each.
Answer:
Single-row functions operate on each row. Example: UCASE(), ROUND()
Aggregate functions operate on a group of rows. Example: SUM(), MAX()
20. Write queries to:
a) Display names in lowercase
b) Display first 4 characters of Cname
c) Display length of each name in EMPLOYEE
Answer:
a) SELECT LCASE(Ename) FROM EMPLOYEE;
b) SELECT MID(Cname, 1, 4) FROM CUSTOMER;
c) SELECT LENGTH(Ename) FROM EMPLOYEE;
5 MARKS QUESTIONS
QUESTION 1
Given Table: STUDENT
a. Write a CREATE TABLE command to create the STUDENT table with appropriate data types.
CHAPTER 9 STRUCTURED QUERY LANGUAGE (SQL) II PUC
ANSWER 1
a.
b.
c.
d.
UPDATE STUDENT
SET GUID = '101010101010'
WHERE RollNumber = 3;
e.
QUESTION 2
Given Table: EMPLOYEE
a. Write the CREATE TABLE command for EMPLOYEE with relevant types.
ANSWER 2
a.
b.
c.
CHAPTER 9 STRUCTURED QUERY LANGUAGE (SQL) II PUC
d.
UPDATE EMPLOYEE
SET Salary = 32000
WHERE Ename = 'Chetan';
e.
QUESTION 3
Given Table: GUARDIAN
ANSWER 3
a.
CHAPTER 9 STRUCTURED QUERY LANGUAGE (SQL) II PUC
b.
c.
d.
UPDATE GUARDIAN
SET GPhone = '9012345678'
WHERE GUID = '222222222222';
e.
QUESTION 4
Given Table: INVENTORY
ANSWER 4
a.
b.
c.
d.
UPDATE INVENTORY
SET Price = 360000.00
WHERE CarId = 'C02';
e.
QUESTION 5
Given Table: SALE
ANSWER 5
a.
b.
c.
d.
UPDATE SALE
SET SalePrice = 550000.00
WHERE InvoiceNo = 'I002';
e.
QUESTION 6
Given Table: CUSTOMER
ANSWER 6
a.
CHAPTER 9 STRUCTURED QUERY LANGUAGE (SQL) II PUC
b.
c.
d.
UPDATE CUSTOMER
SET Phone = '9876543210'
WHERE CustName = 'Ravi Verma';
e.
QUESTION 7
Given Table: PRODUCT
ANSWER 7
a.
b.
c.
d.
UPDATE PRODUCT
SET Stock = 12
WHERE ProdName = 'Monitor';
e.
QUESTION 8
Given Table: BOOK
ANSWER 8
a.
b.
c.
d.
UPDATE BOOK
SET Price = 500
WHERE Title = 'Python Programming';
e.
QUESTION 9
Given Table: SUPPLIER
ANSWER 9
a.
CHAPTER 9 STRUCTURED QUERY LANGUAGE (SQL) II PUC
b.
c.
d.
UPDATE SUPPLIER
SET City = 'Noida'
WHERE Name = 'Om Supplies';
e.
QUESTION 10
Given Table: ATTENDANCE
1 2024-08-01 P
2 2024-08-01 A
ANSWER 10
a.
b.
c.
d.
UPDATE ATTENDANCE
SET Status = 'P'
WHERE RollNo = 2 AND Date = '2024-08-01';
e.
QUESTION 11
Given Table: MARKS
CHAPTER 9 STRUCTURED QUERY LANGUAGE (SQL) II PUC
1 Math 85
2 Math 78
1 Science 90
ANSWER 11
a.
b.
c.
d.
CHAPTER 9 STRUCTURED QUERY LANGUAGE (SQL) II PUC
UPDATE MARKS
SET Marks = 82
WHERE RollNo = 2 AND Subject = 'Math';
e.
QUESTION 12
Given Table: PRODUCT
ANSWER 12
a.
Price INT,
Quantity INT
);
b.
c.
d.
UPDATE PRODUCT
SET Quantity = 120
WHERE Name = 'Pen';
e.
QUESTION 13
Given Table: SALES
ANSWER 13
a.
b.
c.
d.
UPDATE SALES
SET Amount = 180
WHERE SaleID = 'S003';
e.
QUESTION 14
Given Table: ATTENDANCE
CHAPTER 9 STRUCTURED QUERY LANGUAGE (SQL) II PUC
2024-08-01 1 P
2024-08-01 2 A
2024-08-02 1 P
ANSWER 14
a.
b.
c.
d.
CHAPTER 9 STRUCTURED QUERY LANGUAGE (SQL) II PUC
UPDATE ATTENDANCE
SET Status = 'P'
WHERE RollNo = 2 AND Date = '2024-08-01';
e.
QUESTION 15
Given Table: EMPLOYEE
ANSWER 15
a.
CHAPTER 9 STRUCTURED QUERY LANGUAGE (SQL) II PUC
b.
c.
d.
UPDATE EMPLOYEE
SET Salary = 46000
WHERE Name = 'Rohan';
e.
QUESTION 16
Given Table: GUARDIAN
ANSWER 16
a.
b.
c.
d.
UPDATE GUARDIAN
SET Income = 310000
WHERE GUID = 'G003';
e.
QUESTION 17
Given Table: LIBRARY
CHAPTER 9 STRUCTURED QUERY LANGUAGE (SQL) II PUC
ANSWER 17
a.
b.
c.
d.
CHAPTER 9 STRUCTURED QUERY LANGUAGE (SQL) II PUC
UPDATE LIBRARY
SET Price = 470
WHERE Title = 'DBMS Concepts';
e.
QUESTION 18
Given Table: PURCHASE
ANSWER 18
a.
CHAPTER 9 STRUCTURED QUERY LANGUAGE (SQL) II PUC
b.
c.
d.
UPDATE PURCHASE
SET Quantity = 70
WHERE Item = 'Eraser';
e.
QUESTION 19
Given Table: ORDERS
ANSWER 19
a.
b.
c.
d.
UPDATE ORDERS
SET Amount = 4600
WHERE OrderID = 'O003';
e.
QUESTION 20
Given Table: CLASSMARKS
CHAPTER 9 STRUCTURED QUERY LANGUAGE (SQL) II PUC
101 English 88
102 English 92
103 English 80
ANSWER 20
d. UPDATE CLASSMARKS
SET Marks = 85
WHERE RollNo = 103;
b)
- ORDER BY: Sorts query results based on one or more columns.
- GROUP BY: Groups rows with identical values for aggregate functions.
c)
d) Cartesian Product: The result of combining every row from one table with every row from another
table.
e)
- ALTER changes table structure.
- UPDATE changes table content.
- DELETE removes specific rows.
- DROP removes entire table.
f)
i) DAYNAME()
ii) MID() or SUBSTRING()
iii) MONTHNAME()
iv) UPPER() or UCASE()
CHAPTER 9 STRUCTURED QUERY LANGUAGE (SQL) II PUC
a)
SELECT POW(2,3);
→8
b)
SELECT ROUND(342.9234,-1);
→ 340
c)
→ 23
d)
e)
Given table MOVIE with columns: MovieID, MovieName, Category, ReleaseDate, ProductionCost, Busi-
nessCost
a)
b)
c)
CHAPTER 9 STRUCTURED QUERY LANGUAGE (SQL) II PUC
d)
e)
SELECT MovieID, MovieName, ProductionCost FROM MOVIE WHERE ProductionCost > 10000 AND
𝗌 ProductionCost < 100000;
f)
g)
a)
b)
DESC TEAM;
e)
f)
g)
SELECT MatchID FROM MATCH_DETAILS WHERE FirstTeamScore > 70 AND SecondTeamScore > 70;
b)
SELECT MatchID FROM MATCH_DETAILS WHERE FirstTeamScore < 70 AND SecondTeamScore > 70;
c)
d)
e)
ALTER TABLE COST ADD CONSTRAINT FK_UCode FOREIGN KEY (UCode) REFERENCES
𝗌 UNIFORM(UCode);
ALTER TABLE UNIFORM ADD CONSTRAINT chk_UName CHECK (UName IS NOT NULL);
ALTER TABLE COST ADD CONSTRAINT chk_price_gt_zero CHECK (Price > 0);
a)
c)
SELECT PCode, PName, UPrice FROM Product ORDER BY PName DESC, UPrice ASC;
d)
e)
OR
CHAPTER 9 STRUCTURED QUERY LANGUAGE (SQL) II PUC
f)
g)
h)
i)
j)
k)
a)
b)
or
CHAPTER 9 STRUCTURED QUERY LANGUAGE (SQL) II PUC
c)
SELECT CarName FROM INVENTORY WHERE FuelType = 'Petrol' ORDER BY Price DESC LIMIT 1;
d)
e)