Courses
Courses for Kids
Free study material
Offline Centres
More
Store Icon
Store

Important Questions and Answers for Class 12 Computer Science Chapter 9 Structured Query Language (SQL) | 2026-27

ffImage
banner

Strengthen Your SQL Skills with Class 12 Computer Science Chapter 9 Important Questions and Answers

Writing SQL queries becomes easier when students understand how different commands work with database tables. Class 12 Computer Science Chapter 9, Structured Query Language (SQL), focuses on creating and modifying tables, inserting and retrieving records, applying conditions and using SQL functions. 


It also introduces grouping, ordering and joining data from related tables, helping students understand how databases are managed through SQL statements.


Vedantu's Class 12 Computer Science Chapter 9 Important Questions and Answers help students practise SQL queries, commands and database operations through solved MCQs and descriptive questions. For more practice, explore Class 12 Computer Science Important Questions and Class 12 Important Questions for all subjects.

Access Class 12 Computer Science Chapter 9 Important Questions PDF Download

Class 12 Computer Science Chapter 9 (MCQ)Multiple Choice Questions

Q1. Which SQL statement is used to retrieve data from a table?

(a) INSERT

(b) SELECT

(c) UPDATE

(d) DELETE

Answer: (b) SELECT

Explanation: The SELECT statement retrieves data from one or more tables. It can display all columns, selected columns or records that satisfy specified conditions.


Q2. Which of the following MySQL data types is used to store variable-length character strings?

(a) CHAR

(b) INT

(c) VARCHAR

(d) DATE

Answer: (c) VARCHAR

Explanation: VARCHAR(n) stores strings of variable length, up to the specified maximum. For example, VARCHAR(20) can store a student's name containing up to 20 characters.


Q3. Which constraint ensures that a column cannot contain NULL values?

(a) UNIQUE

(b) DEFAULT

(c) NOT NULL

(d) FOREIGN KEY

Answer: (c) NOT NULL

Explanation: The NOT NULL constraint prevents missing or unknown values from being stored in a column. For example, SName in the STUDENT table can be defined with NOT NULL.


Q4. Which SQL clause is used to arrange records in ascending or descending order?

(a) GROUP BY

(b) WHERE

(c) ORDER BY

(d) HAVING

Answer: (c) ORDER BY

Explanation: ORDER BY sorts query results according to specified columns. The default order is ascending, while DESC specifies descending order.


Q5. Which SQL function returns the total number of records in a table?

(a) SUM()

(b) COUNT(*)

(c) MAX()

(d) AVG()

Answer: (b) COUNT(*)

Explanation: COUNT(*) counts the rows in a table, including rows containing NULL values in individual columns.


Class 12 Computer Science Chapter 9 Very Short Answer Questions

Q6. What is Structured Query Language (SQL)? Mention its main uses.

Answer:

Structured Query Language (SQL) is a query language used to access and manage data in relational database management systems.


SQL is used to:


  1. Create databases and tables.

  2. Define attributes and constraints.

  3. Insert, update and delete records.

  4. Retrieve information using queries.


MySQL, Oracle and SQL Server are examples of database management systems that support SQL.


Q7. What is the difference between CHAR and VARCHAR data types?

Answer:


CHAR

VARCHAR

Fixed-length character data type

Variable-length character data type

Reserves space for the declared length

Storage depends on the actual string length

Example: CHAR(10)

Example: VARCHAR(30)


For example, storing 'city' in CHAR(10) involves padding the remaining six character positions with spaces. VARCHAR(30) stores the four-character value without requiring the full declared length.


Q8. What are SQL constraints? Name five commonly used constraints.

Answer:

SQL constraints are restrictions applied to the values stored in table columns to maintain data correctness.


Five commonly used constraints are:


  1. NOT NULL: Prevents NULL values.

  2. UNIQUE: Ensures distinct values in a column.

  3. DEFAULT: Supplies a default value when none is provided.

  4. PRIMARY KEY: Uniquely identifies each record.

  5. FOREIGN KEY: Establishes a reference to the primary key of another table.


Q9. What is the purpose of the CREATE DATABASE and USE statements?

Answer:

The CREATE DATABASE statement creates a new database, while USE selects an existing database for performing operations.


Example:

CREATE DATABASE StudentAttendance;

USE StudentAttendance;

The first statement creates the StudentAttendance database. The second statement makes it the selected database.


Q10. What is the purpose of the DESCRIBE statement in MySQL?

Answer:

The DESCRIBE statement displays the structure of an existing table, including column names, data types, NULL permissions, keys and default values.


Example:

DESCRIBE STUDENT;

The statement displays the structure of the STUDENT table.


Q11. What is the difference between DELETE and DROP statements?

Answer:


DELETE

DROP

Removes records from a table

Removes a table or database

Table structure remains available

The removed table's structure is also deleted

Can remove selected records using WHERE

Removes the specified table or database


Example:

DELETE FROM STUDENT

WHERE RollNumber = 3;


This removes the selected student's record.


DROP TABLE STUDENT;


This removes the entire STUDENT table.


Q12. What is the purpose of the DISTINCT keyword in SQL?

Answer:

DISTINCT removes duplicate values from the result of a SELECT query.


Example:

SELECT DISTINCT DeptId

FROM EMPLOYEE;


This displays each department ID only once, even if several employees belong to the same department.


Q13. What is the difference between WHERE and HAVING clauses?

Answer:

The WHERE clause filters individual records based on specified conditions.


The HAVING clause filters groups of records after applying GROUP BY.


Example using WHERE:

SELECT *

FROM EMPLOYEE

WHERE Salary > 5000;


Example using HAVING:

SELECT Paymentmode, COUNT(*)

FROM SALE

GROUP BY Paymentmode

HAVING COUNT(*) > 1;


The first query selects employees meeting a salary condition. The second selects payment-mode groups containing more than one sale.


Q14. What is the difference between single-row and aggregate functions?

Answer:


Single-Row Functions

Aggregate Functions

Operate on individual values or rows

Operate on sets or groups of rows

Return a result for each input row

Return one result for a group

Examples: POWER(), ROUND(), UCASE()

Examples: SUM(), AVG(), COUNT()


Single-row functions are also called scalar functions, while aggregate functions are called multiple-row functions.


Q15. What is a Cartesian product in a relational database?

Answer:

A Cartesian product combines every tuple of one relation with every tuple of another relation.

If the first relation contains m tuples and the second contains n tuples, the Cartesian product contains:


$m\times n$

tuples.


In SQL, a Cartesian product can be generated by including two tables in the FROM clause without a condition connecting them.


Class 12 Computer Science Chapter 9 Short Answer Questions and SQL Commands

Q16. Write SQL statements to create the STUDENT table with appropriate data types and a primary key.

Answer:

The STUDENT table contains RollNumber, SName, SDateofBirth and GUID.


CREATE TABLE STUDENT (

    RollNumber INT,

    SName VARCHAR(20),

    SDateofBirth DATE,

    GUID CHAR(12),

    PRIMARY KEY (RollNumber)

);


Explanation:

  • RollNumber stores integer values and is the primary key.

  • SName stores names of up to 20 characters.

  • SDateofBirth stores dates in YYYY-MM-DD format.

  • GUID stores a fixed-length, 12-character guardian ID.


The primary key ensures that each student is uniquely identified by RollNumber.


Q17. Write SQL statements to add a primary key and a foreign key using ALTER TABLE.

Answer:

To make GUID the primary key of GUARDIAN:

ALTER TABLE GUARDIAN

ADD PRIMARY KEY (GUID);

To add GUID as a foreign key in STUDENT:

ALTER TABLE STUDENT

ADD FOREIGN KEY (GUID)

REFERENCES GUARDIAN(GUID);


Explanation: The first statement uniquely identifies each guardian. The second creates a relationship between STUDENT and GUARDIAN using GUID.


The referenced GUARDIAN table must already exist, and the linked columns must have compatible data types and sizes.


Q18. Write SQL statements to add, modify and remove an attribute from the GUARDIAN table.

Answer:

1. Add an Income attribute of type INT.

ALTER TABLE GUARDIAN

ADD Income INT;

2. Change GAddress from VARCHAR(30) to VARCHAR(40).

ALTER TABLE GUARDIAN

MODIFY GAddress VARCHAR(40);

3. Remove the Income attribute.

ALTER TABLE GUARDIAN

DROP Income;


Explanation: ALTER TABLE changes the structure of an existing table. It can add or remove columns and modify their data types or constraints without recreating the entire table.


Q19. Write SQL statements to insert the records of Atharv Ahuja and Taleem Shah into the STUDENT table.

Answer:

1. Insert Atharv Ahuja's details.


INSERT INTO STUDENT

VALUES (

    1,

    'Atharv Ahuja',

    '2003-05-15',

    '444444444444'

);


2. Insert Taleem Shah's details with NULL as GUID.


INSERT INTO STUDENT

VALUES (

    3,

    'Taleem Shah',

    '2002-02-28',

    NULL

);


Explanation:

INSERT INTO is used to add records to a table.


Text and date values must be enclosed in single quotes. The GUID field for Taleem Shah contains NULL because the guardian ID is not provided.

The referenced guardian record for Atharv must already exist if the foreign key constraint is enforced.


Q20. Write an SQL query to retrieve the name and date of birth of the student whose roll number is 1.

Answer:


SELECT SName, SDateofBirth

FROM STUDENT

WHERE RollNumber = 1;


Output:


SName

SDateofBirth

Atharv Ahuja

2003-05-15


Explanation:

SELECT specifies the columns to retrieve, FROM identifies the table, and WHERE selects the record satisfying the condition RollNumber = 1.


Class 12 Computer Science Chapter 9 Long Answer Questions

For Questions 21–24, consider the EMPLOYEE table used in the OFFICE database.


EmpNo

Ename

Salary

Bonus

DeptId

101

Aaliya

10000

234

D02

102

Kritika

60000

123

D01

103

Shabbir

45000

566

D01

104

Gurpreet

19000

565

D04

105

Joseph

34000

875

D03

106

Sanya

48000

695

D02

107

Vergese

15000

NULL

D01

108

Nachaobi

29000

NULL

D05

109

Daribha

42000

NULL

D04

110

Tanya

50000

467

D05


21. Write an SQL query to display employee names and their annual income. Display the column headings as Name and Annual Income.

Answer:


SELECT Ename AS Name,

       Salary * 12 AS 'Annual Income'

FROM EMPLOYEE;


Output:


Name

Annual Income

Aaliya

120000

Kritika

720000

Shabbir

540000

Gurpreet

228000

Joseph

408000

Sanya

576000

Vergese

180000

Nachaobi

348000

Daribha

504000

Tanya

600000


Explanation:

The expression Salary * 12 calculates annual income using the monthly salary. AS provides a temporary name for the output column.


The calculated Annual Income column is displayed in the query result; it is not permanently added to the EMPLOYEE table.


Q22. Write an SQL query to display the names and department IDs of employees earning between ₹20,000 and ₹50,000.

Answer:


SELECT Ename, DeptId

FROM EMPLOYEE

WHERE Salary BETWEEN 20000 AND 50000;


Output:


Ename

DeptId

Shabbir

D01

Joseph

D03

Sanya

D02

Nachaobi

D05

Daribha

D04

Tanya

D05


Explanation:

BETWEEN selects values within a specified range, including both boundary values.


The condition is equivalent to:


WHERE Salary >= 20000

AND Salary <= 50000;


Q23. Write SQL queries to display employees in departments D01, D02 and D04, and to exclude employees belonging to D01 and D02.

Answer:

1. Display employees from D01, D02 and D04.

SELECT *

FROM EMPLOYEE

WHERE DeptId IN ('D01', 'D02', 'D04');


2. Display employees except those in D01 and D02.

SELECT *

FROM EMPLOYEE

WHERE DeptId NOT IN ('D01', 'D02');


Explanation:

IN checks whether a value matches any of the specified values. NOT IN excludes records matching those values.


The first query selects employees from three departments, while the second excludes employees of D01 and D02.


Q24. Write SQL queries to display employees in descending order of salary and to find employees whose bonus is NULL.

Answer:

1. Display employees in descending order of salary.

SELECT *

FROM EMPLOYEE

ORDER BY Salary DESC;


2. Display employees whose bonus is NULL.

SELECT *

FROM EMPLOYEE

WHERE Bonus IS NULL;


Output of the second query:


EmpNo

Ename

Salary

Bonus

DeptId

107

Vergese

15000

NULL

D01

108

Nachaobi

29000

NULL

D05

109

Daribha

42000

NULL

D04


Explanation:

ORDER BY Salary DESC arranges employees from highest to lowest salary.


IS NULL is used to identify missing or unknown values. The condition Bonus = NULL should not be used to test for NULL.


Q25. Explain UPDATE and DELETE statements with SQL examples.

Answer:

UPDATE Statement

UPDATE modifies existing data in a table.

For example, to increase the salary of employee number 101 to ₹15,000:

UPDATE EMPLOYEE

SET Salary = 15000

WHERE EmpNo = 101;


DELETE Statement

DELETE removes records from a table.

For example, to delete the record of employee number 101:

DELETE FROM EMPLOYEE

WHERE EmpNo = 101;


Explanation:

  • UPDATE changes values in existing records.

  • DELETE removes the selected records.

  • WHERE identifies the records affected by the operation.


If WHERE is omitted, UPDATE may modify all rows and DELETE may remove all rows from the table.


These commands should be executed independently when practising each operation.


Important Topics Covered in Class 12 Computer Science Chapter 9 Structured Query Language (SQL)

Chapter 9 explains how SQL is used to create, modify and retrieve information from relational databases.


The NCERT chapter includes practical examples of SQL commands and queries using database tables, making syntax and query writing important areas for exam preparation.


The following table highlights the major topics and concepts students should practise.


Important Topics

Key Concepts to Focus On

Introduction to SQL

Purpose of SQL and its use in relational database management systems

SQL Data Types

Numeric, character, date and other commonly used MySQL data types

Data Definition Language (DDL)

CREATE, ALTER and DROP commands

Data Constraints

PRIMARY KEY, FOREIGN KEY, NOT NULL, UNIQUE and related restrictions

Data Manipulation Language (DML)

INSERT, UPDATE and DELETE statements

Data Query Language (DQL)

SELECT statements to retrieve data

Filtering Records

WHERE, comparison operators and logical conditions

Sorting Query Results

ORDER BY, ascending and descending order

SQL Functions

Single-row functions and aggregate functions

Aggregate Functions

COUNT(), SUM(), AVG(), MIN() and MAX()

Grouping Data

GROUP BY and HAVING clauses

Working with Multiple Tables

Cartesian product, joins and retrieving related records


How Vedantu's Important Questions and Answers Help You Practise SQL in Chapter 9

Vedantu's Class 12 Computer Science Chapter 9 Important Questions and Answers help students understand SQL commands through solved queries, database examples and application-based practice.


  • SQL Command-Based Questions: Practice CREATE, ALTER, INSERT, UPDATE, DELETE and SELECT statements with explanations of their uses.

  • MCQs for Concept Revision: Test your understanding of SQL data types, constraints, functions, operators and different categories of SQL commands.

  • Query-Writing Practice: Learn to write SQL statements for filtering, sorting, grouping and retrieving records from database tables.

  • Function and Output-Based Questions: Understand how aggregate functions, single-row functions and SQL clauses affect query results.

  • NCERT-Based Application Questions: Practise problems involving database tables, joins, record updates and retrieving information based on given conditions.


These important questions and solved answers help students recognise SQL syntax errors, understand the logic behind database queries and build confidence in answering both conceptual and practical questions.


Important Study Material Links for Class 12 Computer Science Chapter 9 Structured Query Language (SQL)


Class 12 Computer Science Chapter-Wise Important Questions

Additional Study Materials for Class 12 Computer Science

FAQs on Important Questions and Answers for Class 12 Computer Science Chapter 9 Structured Query Language (SQL) | 2026-27

1. What are the most important SQL commands to practise in Class 12 Computer Science Chapter 9?

Important SQL commands include CREATE, ALTER, DROP, INSERT, UPDATE, DELETE and SELECT. Students should also understand WHERE, ORDER BY, GROUP BY and HAVING, along with aggregate functions and joins. 


These topics help students solve query-writing and application-based questions.

2. What is the difference between DDL, DML and DQL in Chapter 9 SQL?

DDL (Data Definition Language) commands such as CREATE, ALTER and DROP define or modify database structures. DML (Data Manipulation Language) commands such as INSERT, UPDATE and DELETE change stored records. DQL (Data Query Language) uses SELECT to retrieve information from database tables.

3. What are the most common mistakes in Class 12 SQL answers, and how can students avoid them?

Common mistakes include:

  • Using incorrect SQL command syntax or misspelling keywords.

  • Confusing WHERE and HAVING clauses.

  • Forgetting quotation marks around string values.

  • Using GROUP BY or ORDER BY incorrectly.

  • Writing incorrect conditions with AND and OR operators.

Students can avoid these mistakes by practising NCERT SQL queries, checking column names and understanding the purpose of each command.

4. How can students quickly revise Class 12 Computer Science Chapter 9 Structured Query Language (SQL)?

Students can revise Chapter 9 by:

  • Reviewing SQL commands such as CREATE, ALTER, INSERT, UPDATE and SELECT.

  • Practising queries using WHERE, ORDER BY, GROUP BY and HAVING.

  • Revising aggregate functions such as COUNT(), SUM() and AVG().

  • Solving MCQs and query-based questions from NCERT exercises.

  • Using Vedantu's Chapter 9 Important Questions and Answers to practise different question formats.

5. Can students receive partial marks for SQL questions if their final query is incorrect?

Partial marks may be awarded for correctly written SQL statements or steps, depending on the marking scheme. Students should use the correct commands, table names, column names and conditions to improve their chances of receiving marks.

6. Should students use NCERT textbook page numbers while revising Chapter 9 SQL?

Yes, noting NCERT textbook page numbers can help students quickly find SQL definitions, command examples and practice exercises. However, understanding query syntax and practising SQL statements is more important than memorising page numbers.

📌 Add Vedantu as a preferred source on Google