Skip to content
TestMacher
Chapter 5 · Class 12 Computer Science

SQL Queries — Important Questions

33 questions With answers CBSE format

SUMMARY: This chapter focuses on teaching students how to write and execute SQL queries to manage and manipulate databases.
KEY TOPICS: SQL syntax, SELECT statement, WHERE clause, JOIN operations, GROUP BY clause, ORDER BY clause, INSERT statement, UPDATE statement, DELETE statement, aggregate functions

Q1 1 Mark

Which SQL command is used to retrieve data from a database?

AGET
BSELECT
CFETCH
DRETRIEVE
Check answerHide answer
Correct answer: Option 2 — SELECT
Q2 1 Mark

Which SQL clause is used to filter records?

AWHERE
BFILTER
CHAVING
DIF
Check answerHide answer
Correct answer: Option 1 — WHERE
Q3 1 Mark

Which SQL keyword is used to sort the result-set in ascending order by default?

ASORT BY
BGROUP BY
CORDER BY
DLIST BY
Check answerHide answer
Correct answer: Option 3 — ORDER BY
Q4 1 Mark

The SQL command used to add a new row to a table is:

AADD
BAPPEND
CINSERT
DCREATE
Check answerHide answer
Correct answer: Option 3 — INSERT
Q5 1 Mark

Which SQL function returns the total number of rows in a column?

ASUM
BCOUNT
CTOTAL
DLEN
Check answerHide answer
Correct answer: Option 2 — COUNT
Q6 3 Marks

Differentiate between DDL and DML commands with two examples each.

Q7 3 Marks

Write a SQL query to display all rows from the table employee.

Q8 3 Marks

Differentiate between WHERE and HAVING clauses.

Q9 3 Marks

Write a SQL query to find the total number of employees in each department from a table employee(emp_id name dept salary).

Q10 3 Marks

Explain the use of DISTINCT keyword in SQL with one example.

Q11 6 Marks

Discuss any five SQL aggregate functions with examples on a sample employee table.

Q12 6 Marks

Differentiate between INNER JOIN LEFT JOIN and RIGHT JOIN with one example each.

Q13 6 Marks

Write SQL queries to: (a) create a table student (b) insert 3 rows (c) update marks of one student (d) delete a student (e) display students with marks > 80.

Q14 6 Marks

Explain GROUP BY and HAVING clauses with examples.

Q15 6 Marks

Discuss constraints in SQL — PRIMARY KEY FOREIGN KEY UNIQUE NOT NULL CHECK DEFAULT — with one example each.

Q16 6 Marks

Differentiate between DDL and DML SQL commands in tabular form with examples.

Q17 1 Mark

Assertion (A): SELECT is a DQL (Data Query Language) command.

Reason (R): It is used to retrieve data from one or more tables.

Show explanationHide explanation
Correct answer: Option 1 — Both A and R are true, and R is the correct explanation of A.
Q18 1 Mark

Assertion (A): GROUP BY groups rows with same value in a column.

Reason (R): It is often used with aggregate functions.

Show explanationHide explanation
Correct answer: Option 1 — Both A and R are true, and R is the correct explanation of A.
Q19 1 Mark

Assertion (A): COUNT(*) returns the total number of rows including NULLs.

Reason (R): COUNT(column) ignores NULL values in that column.

Show explanationHide explanation
Correct answer: Option 1 — Both A and R are true, and R is the correct explanation of A.
Q20 1 Mark

Assertion (A): DELETE removes rows from a table.

Reason (R): DROP removes the entire table including its structure.

Show explanationHide explanation
Correct answer: Option 1 — Both A and R are true, and R is the correct explanation of A.
Q21 1 Mark

Assertion (A): The LIKE operator is used for pattern matching.

Reason (R): Wildcard % matches any sequence of characters.

Show explanationHide explanation
Correct answer: Option 1 — Both A and R are true, and R is the correct explanation of A.
Q22 1 Mark

Statement 1: DDL commands include CREATE ALTER and DROP.

Statement 2: They define and modify the structure of a database.

Show answerHide answer
Correct answer: Option 1 — Both statements are true.
Q23 1 Mark

Statement 1: DML commands include INSERT UPDATE and DELETE.

Statement 2: They modify the data within tables.

Show answerHide answer
Correct answer: Option 1 — Both statements are true.
Q24 1 Mark

Statement 1: WHERE filters rows before grouping.

Statement 2: HAVING filters groups after aggregation.

Show answerHide answer
Correct answer: Option 1 — Both statements are true.
Q25 1 Mark

Statement 1: A NULL value is different from zero or empty string.

Statement 2: It represents missing or unknown data.

Show answerHide answer
Correct answer: Option 1 — Both statements are true.
Q26 1 Mark

Statement 1: JOIN combines rows from two or more tables based on a related column.

Statement 2: Different types include INNER LEFT RIGHT and FULL OUTER joins.

Show answerHide answer
Correct answer: Option 1 — Both statements are true.
Q27 3 Marks
A company has an employee table with columns emp_id name dept salary. The HR manager wants to write SQL queries to: (1) list all employees in HR (2) find the average salary in each department (3) get the top 3 highest-paid employees (4) count employees per department.
  1. Which SQL command retrieves data from a table?
    ASELECT
    BGET
    CFETCH
    DRETRIEVE
  2. Which clause is used to filter individual rows?
    AWHERE
    BHAVING
    CGROUP BY
    DORDER BY
  3. Write the SQL queries for all four HR requirements.
Show answersHide answers
1. Option 1 — SELECT
2. Option 1 — WHERE
3. (1) SELECT * FROM employee WHERE dept = 'HR'. (2) SELECT dept AVG(salary) FROM employee GROUP BY dept. (3) SELECT * FROM employee ORDER BY salary DESC LIMIT 3. (4) SELECT dept COUNT(*) FROM employee GROUP BY dept. WHERE filters individual rows; GROUP BY groups rows; HAVING filters groups; ORDER BY sorts; LIMIT restricts the count.
Q28 6 Marks

For the sample employee table compute the result of each SQL query.

emp_idnamedeptsalary
1AnilIT50000
2BobbyHR40000
3ChitraHR35000
4GeetaIT60000
5HariSales40000
Q29 5 Marks

Match each SQL clause with its purpose.

ClausePurpose
SELECT?
WHERE?
GROUP BY?
HAVING?
ORDER BY?
LIMIT?
Q30 5 Marks

For the sample table evaluate each SQL aggregate query.

QueryResult
COUNT(*)?
SUM(salary)?
AVG(salary)?
MAX(salary)?
MIN(salary)?
COUNT(DISTINCT dept)?
Q31 5 Marks

Match SQL command type (DDL/DML/DCL/DQL/TCL) for each.

CommandType
CREATE?
INSERT?
SELECT?
GRANT?
COMMIT?
DROP?
UPDATE?
Q32 3 Marks

Study the SQL JOIN Venn diagrams and answer:

SQL Queries figure
  1. Which JOIN returns only matching rows from both tables?
    AINNER JOIN
    BLEFT JOIN
    CFULL JOIN
    DCROSS JOIN
  2. Which JOIN returns all rows from the left table plus matches from the right?
    AINNER
    BLEFT
    CRIGHT
    DFULL
  3. Differentiate between INNER LEFT RIGHT and FULL JOINs with examples.
Show answersHide answers
1. Option 1 — INNER JOIN
2. Option 2 — LEFT
3. INNER JOIN returns only matching rows from both tables (intersection). LEFT JOIN returns all rows from left + matching from right (NULL for non-matching). RIGHT JOIN is the mirror. FULL JOIN returns all rows from both tables. CROSS JOIN returns Cartesian product. JOINs combine rows based on a related column (typically primary key foreign key).
Q33 3 Marks

Study the SQL execution order diagram and answer:

SQL Queries figure
  1. Which clause is executed FIRST?
    ASELECT
    BFROM
    CWHERE
    DORDER BY
  2. Which clause filters AGGREGATED groups?
    AWHERE
    BHAVING
    CGROUP BY
    DORDER BY
  3. Discuss the logical execution order of SQL clauses and explain WHERE vs HAVING.
Show answersHide answers
1. Option 2 — FROM
2. Option 2 — HAVING
3. SQL clauses are written in the order SELECT FROM WHERE GROUP BY HAVING ORDER BY LIMIT but executed in a different logical order: FROM WHERE GROUP BY HAVING SELECT ORDER BY LIMIT. This means WHERE filters individual rows BEFORE grouping while HAVING filters groups AFTER aggregation. Knowing the execution order helps write correct queries.

Make a full Computer Science paper on SQL Queries.

Pick the question mix, set the marks, hit generate. You get a ready-to-print paper with an answer key.

Generate your paper — free