Structured Query Language Quiz Class 12

🗃️ Structured Query Language (SQL) Quiz — Class 12 Computer Science (Code 083)

Practice 20 CBSE Class 12 Computer Science (Code 083) MCQs on SQL — DDL & DML, data types (CHAR, VARCHAR, INT, FLOAT), constraints (NOT NULL, UNIQUE, PRIMARY KEY), SELECT/WHERE/DISTINCT, GROUP BY/HAVING, aggregate functions (MAX, MIN, AVG, SUM, COUNT), LIKE/BETWEEN, and joins (Cartesian product, equi-join, natural join).

Every query below has been tested against a real database. This set includes 1 board-style predict-the-output question with sample table data. Tap any question to reveal the answer with a clear explanation.

🗃️ SQL Basics🏗️ DDL🔤 Data Types🚧 Constraints✏️ DML📊 Aggregate Functions🔗 Joins⭐ Board-Style Programs
Q1
🗃️ SQL Basics

What does SQL stand for?

  1. Standard Query Language
  2. Simple Query Language
  3. Structured Query Language
  4. Structured Query Logic
Show Answer & Explanation

✅ Answer: (c) Structured Query Language

SQL stands for Structured Query Language — the standard language used to create, manage, and query relational databases.

Q2
🏗️ DDL

What is the purpose of Data Definition Language (DDL) in SQL?

  1. To manipulate data
  2. To retrieve data from the database
  3. To define and manage the structure of a database
  4. To perform mathematical operations
Show Answer & Explanation

✅ Answer: (c) To define and manage the structure of a database

DDL commands (CREATE, ALTER, DROP) are used to define and manage the structure of databases and tables — as opposed to DML, which manipulates the actual data inside them.

Q3
🔤 Data Types

Which data type is used for storing variable-length character strings in SQL?

  1. CHAR(n)
  2. INT
  3. VARCHAR(n)
  4. FLOAT
Show Answer & Explanation

✅ Answer: (c) VARCHAR(n)

VARCHAR(n) stores text up to n characters, using only as much space as the actual text needs. CHAR(n), by contrast, always reserves the full n characters, padding shorter values with spaces.

Q4
🚧 Constraints

What does the NOT NULL constraint specify in SQL?

  1. Allows NULL values in the column
  2. Disallows NULL values in the column
  3. Enforces unique values in the column
  4. Creates a primary key
Show Answer & Explanation

✅ Answer: (b) Disallows NULL values in the column

NOT NULL forces a column to always have a value — attempting to insert a row without one for that column will be rejected.

Q5
🏗️ DDL

How can you create a new database in SQL?

  1. CREATE DATABASE database_name;
  2. USE DATABASE database_name;
  3. SHOW DATABASES;
  4. DROP DATABASE database_name;
Show Answer & Explanation

✅ Answer: (a) CREATE DATABASE database_name;

CREATE DATABASE database_name; is the correct command. USE switches to an existing database, SHOW DATABASES lists them, and DROP DATABASE deletes one entirely.

Q6
✏️ DML

What is the purpose of the SELECT statement in SQL?

  1. To insert data into a table
  2. To update data in a table
  3. To retrieve data from a table
  4. To delete data from a table
Show Answer & Explanation

✅ Answer: (c) To retrieve data from a table

SELECT is used purely to retrieve (query) data from one or more tables — it’s the most frequently used SQL statement.

Q7
✏️ DML

What is the meaning of the DISTINCT clause in SQL?

  1. Retrieves all records from a table
  2. Retrieves unique values from a specified column
  3. Deletes duplicate records from a table
  4. Updates existing records in a table
Show Answer & Explanation

✅ Answer: (b) Retrieves unique values from a specified column

DISTINCT filters out repeated values, returning only the unique ones from the specified column(s) — e.g. SELECT DISTINCT Class FROM Students; lists each class name just once, no matter how many students are in it.

Q8
✏️ DML

How can you filter data using the WHERE clause in SQL?

  1. SELECT DISTINCT column_name FROM table_name WHERE condition;
  2. SELECT * FROM table_name WHERE condition;
  3. DELETE FROM table_name WHERE condition;
  4. UPDATE table_name SET column_name = value WHERE condition;
Show Answer & Explanation

✅ Answer: (b) SELECT * FROM table_name WHERE condition;

SELECT * FROM table_name WHERE condition; is the standard pattern to retrieve only the rows matching a given condition. (The other three options also correctly use WHERE, but for DELETE/UPDATE purposes rather than a basic SELECT filter.)

Q9
📊 Aggregate Functions

What is the purpose of the GROUP BY clause in SQL?

  1. To sort data in ascending order
  2. To group rows that have the same values in specified columns
  3. To join two tables
  4. To add a new column to a table
Show Answer & Explanation

✅ Answer: (b) To group rows that have the same values in specified columns

GROUP BY collects rows sharing the same value in a given column into groups — almost always paired with an aggregate function like COUNT(), SUM(), or AVG() to summarize each group.

Q10
🔗 Joins

How do you perform an equi-join in SQL, following the standard CBSE-taught approach?

  1. SELECT * FROM table1, table2 WHERE table1.column = table2.column;
  2. SELECT * FROM table1 LEFT JOIN table2 ON condition;
  3. SELECT * FROM table1 RIGHT JOIN table2 ON condition;
  4. SELECT * FROM table1 FULL OUTER JOIN table2 ON condition;
Show Answer & Explanation

✅ Answer: (a) SELECT * FROM table1, table2 WHERE table1.column = table2.column;

The CBSE Class 12 syllabus specifically teaches equi-join using comma-separated tables in the FROM clause combined with an equality condition in WHERE — e.g. SELECT * FROM table1, table2 WHERE table1.id = table2.id;. (This question is corrected/clarified from a version whose options included LEFT/RIGHT JOIN syntax, which are outer joins not covered in this syllabus and aren’t examples of an equi-join at all — an equi-join specifically means joining on an equality condition, which the comma+WHERE method demonstrates directly.)

Q11
✏️ DML

What does the UPDATE command in SQL do?

  1. Deletes records from a table
  2. Modifies existing records in a table
  3. Adds a new table to the database
  4. Retrieves data from a table
Show Answer & Explanation

✅ Answer: (b) Modifies existing records in a table

UPDATE changes the values of existing rows that match a given condition — e.g. UPDATE Students SET Marks = 90 WHERE RollNo = 1;.

Q12
✏️ DML

Which keyword is used for removing records from a table in SQL?

  1. DELETE
  2. REMOVE
  3. DROP
  4. ERASE
Show Answer & Explanation

✅ Answer: (a) DELETE

DELETE removes rows matching a condition from a table (e.g. DELETE FROM Students WHERE RollNo = 3;). Note that DROP is different — it removes the entire table structure, not just some rows.

Q13
📊 Aggregate Functions

What is the purpose of the HAVING clause in SQL?

  1. To filter individual rows before any grouping happens
  2. To filter the results of aggregate functions AFTER grouping
  3. To create an alias for a column
  4. To group rows based on a condition
Show Answer & Explanation

✅ Answer: (b) To filter the results of aggregate functions AFTER grouping

HAVING filters groups based on aggregate results (like HAVING AVG(Marks) > 85), applied after GROUP BY has run — this is exactly why HAVING can filter on aggregates, whereas WHERE (which runs before grouping) cannot.

Q14
📊 Aggregate Functions

What does the MAX() function do in SQL?

  1. Calculates the average value
  2. Retrieves the maximum value in a column
  3. Counts the number of rows
  4. Retrieves the minimum value in a column
Show Answer & Explanation

✅ Answer: (b) Retrieves the maximum value in a column

MAX() returns the largest value found in the specified column across the matching rows.

Q15
🔗 Joins

What is a Cartesian product in SQL?

  1. The result of combining every row of one table with every row of another, giving rows = (rows in table1) × (rows in table2)
  2. A type of join that combines rows based on common values only
  3. The process of creating a new table
  4. A function to calculate the average
Show Answer & Explanation

✅ Answer: (a) The result of combining every row of one table with every row of another, giving rows = (rows in table1) × (rows in table2)

A Cartesian product (from SELECT * FROM table1, table2; with no WHERE condition) pairs every row of the first table with every row of the second — a 5-row table joined with a 2-row table produces 5 × 2 = 10 resulting rows.

Q16
🔤 Data Types

What is the key difference between CHAR(n) and VARCHAR(n) in SQL?

  1. They are functionally identical in every way
  2. CHAR(n) always uses exactly n characters of storage (padding shorter values with spaces); VARCHAR(n) uses only as much space as the actual value needs, up to n
  3. VARCHAR(n) always uses exactly n characters; CHAR(n) is variable-length
  4. CHAR(n) can only store numbers, not text
Show Answer & Explanation

✅ Answer: (b) CHAR(n) always uses exactly n characters of storage (padding shorter values with spaces); VARCHAR(n) uses only as much space as the actual value needs, up to n

CHAR(n) is fixed-length — a value shorter than n gets padded with trailing spaces to fill it exactly. VARCHAR(n) is variable-length — it only uses as much storage as the actual text requires, up to the maximum n.

Q17
🔗 Joins

What is the key difference between a natural join and an equi-join?

  1. They are exactly the same thing
  2. A natural join automatically matches columns with the same name across both tables and removes the duplicate column from the result; an equi-join requires an explicit equality condition and keeps both columns
  3. An equi-join can only be used on two identical tables
  4. A natural join always returns zero rows
Show Answer & Explanation

✅ Answer: (b) A natural join automatically matches columns with the same name across both tables and removes the duplicate column from the result; an equi-join requires an explicit equality condition and keeps both columns

A natural join automatically finds columns with matching names in both tables, joins on them, and shows that shared column just once in the result. An equi-join requires you to explicitly write the equality condition (e.g. WHERE t1.id = t2.id), and the result keeps both copies of the joined column (from each table).

Q18
✏️ DML

Which SQL clause is used for pattern matching in text, such as finding all names starting with a specific letter?

  1. MATCH
  2. LIKE
  3. FIND
  4. SEARCH
Show Answer & Explanation

✅ Answer: (b) LIKE

LIKE, combined with wildcard characters, does pattern matching — e.g. WHERE Name LIKE 'R%' matches any name starting with “R” (the % matches any sequence of characters).

Q19
✏️ DML

Which operator is used to select values within a specified range (inclusive of both ends)?

  1. IN
  2. LIKE
  3. BETWEEN
  4. RANGE
Show Answer & Explanation

✅ Answer: (c) BETWEEN

BETWEEN low AND high selects all values falling within that range, including both endpoints — e.g. WHERE Marks BETWEEN 80 AND 90 includes marks of exactly 80 and exactly 90 too.

Q20
⭐ Board-Style Programs

Given a Students table (RollNo, Name, Class, Marks) with 5 rows — two students in Class ’12A’ with marks 85 and 95, and three students spread across ’12A’ and ’12B’ with other marks — what does the following query return?

SELECT Class, AVG(Marks) FROM Students GROUP BY Class;
  1. One row per student, showing their individual marks
  2. One row per class, showing the average marks for each class
  3. A single row with the overall average of all marks combined
  4. An error, since AVG() cannot be used with GROUP BY
Show Answer & Explanation

✅ Answer: (b) One row per class, showing the average marks for each class

GROUP BY Class collects all rows into groups by class, and AVG(Marks) computes the average within each group — so the result has exactly one row per distinct class, each showing that class’s average marks.

Jitendra Singh
✔ Verified Educator

Jitendra Singh

Founder of CBSEPython.in

I help CBSE Class 9–12 students learn Python, Information Technology, Artificial Intelligence and Computer Science through easy notes, quizzes, MCQs and sample papers.

Read More About Me →