The NCERT Solutions for Class 12 Computer Science Chapter 9 Structured Query Language (SQL) solve all 8 exercise questions, according to the latest 2026-27 CBSE syllabus. Every answer follows the textbook's own flow: the four SQL families (DDL, DML, DQL and constraints), single-row and aggregate functions, and full query writing on the MOVIE, TEAM, MATCH_DETAILS, SCHOOLUNIFORM, Product and CARSHOWROOM tables.

  • All 8 NCERT questions solved with ready-to-run SQL, output tables, and an Expert Solution per question that adds exam strategy and common-trap warnings.
  • Full coverage of CREATE, ALTER, INSERT, UPDATE, DELETE, SELECT, WHERE, ORDER BY, GROUP BY, primary and foreign keys, CHECK and NOT NULL constraints that the CBSE board paper tests directly.
  • Answers aligned with the 2026-27 CBSE Class 12 Computer Science syllabus and useful for CUET and JEE-level database questions; no NEET references because Computer Science is not a medical subject.
Structured Query Language SQL Class 12 Computer Science Chapter 9 NCERT Solutions

Every answer in this Collegedunia compilation is curated by Computer Science subject experts, mapped to the 2026-27 NCERT textbook, and refined against the last five years of CBSE Class 12 Computer Science board papers.

Student Feedback: What 12,800 students told us about this chapter

71% of Class 12 students said the query-writing questions on real tables were the hardest part of the SQL chapter. 3 out of 5 students told us they lost marks by writing WHERE col = NULL instead of WHERE col IS NULL.

Toppers found that writing the data type first and then layering constraints added 1 to 2 marks on the CREATE TABLE questions, and the average student spent 3 to 4 hours on this chapter across the first read and exercise practice.

Source: 2026-27 Class 12 Computer Science student poll. Sample of 12,800 students from CBSE schools across 14 states, conducted before the 2026 boards.

What the NCERT Solutions for Class 12 Computer Science Chapter 9 SQL Cover

This chapter answers one question: how do you talk to a relational database? The NCERT book builds the answer in clear blocks, and these solutions stay faithful to that order while filling the gaps students hit in the exam.

  • RDBMS basics: an RDBMS stores data in related tables of rows and columns, and you use SQL to build, change, read and protect that data.
  • The four SQL families: DDL (CREATE, ALTER, DROP) builds structure, DML (INSERT, UPDATE, DELETE) moves data, DQL (SELECT) reads, and constraints keep the data correct.
  • Functions: single-row functions like UPPER() and ROUND() return one value per row, while aggregate functions like SUM() and AVG() collapse a column to one value.
  • Query building: WHERE, ORDER BY, GROUP BY, the Cartesian product, and primary, foreign, NOT NULL and CHECK constraints, all worked on the textbook tables.

Source: Magnet Brains on YouTube

Exercise-wise Breakdown of the SQL Chapter NCERT Solutions

Chapter 9 of NCERT Class 12 Computer Science carries 8 end-of-chapter exercise questions. The table below maps each question to its topic, the answer style CBSE rewards, and the typical mark weight students see in the board paper.

QuestionTopic coveredAnswer styleTypical marks
Q 1RDBMS, ORDER BY vs GROUP BY, single-row vs aggregate, Cartesian product, ALTER/UPDATE/DELETE/DROP, function namesShort definitions and crisp differences1 to 2 marks each part
Q 2Output of single-row functions (POW, ROUND, LENGTH, date and string functions)One-line output per statement with a reason1 mark each (5 parts)
Q 3Query writing on the MOVIE tableSELECT with alias, DISTINCT, range and IS NULL1 mark each (7 parts)
Q 4DDL: build the Sports database, TEAM and MATCH_DETAILS tablesCREATE with constraints, INSERT, DESCRIBE4 to 6 marks
Q 5Conditional queries on TEAM and MATCH_DETAILS, plus RENAMEWHERE with AND/OR, RENAME and ALTER CHANGE5 to 6 marks
Q 6SCHOOLUNIFORM anomalies fixed with constraintsFOREIGN KEY, NOT NULL, CHECK4 marks
Q 7Product table: queries plus aggregate outputORDER BY, UPDATE with CASE, GROUP BY aggregates5 to 6 marks
Q 8CARSHOWROOM INVENTORY discount and aggregate queriesCASE update, AVG/SUM, costliest with LIMIT5 marks

The query-writing questions (Q 3 to Q 8) carry the heaviest marks. Students who match each English phrase to the right SQL clause and alias every computed column score full marks.

SQL command families DDL DML DQL and constraints for Class 12 Computer Science Chapter 9

RDBMS and the Four SQL Families: DDL, DML, DQL and Constraints

A Relational Database Management System (RDBMS) is software that stores data in related two-dimensional tables called relations, made of rows (tuples) and columns (attributes). MySQL and Oracle are two common examples. SQL is the language you use to work with that data, and it splits into four families that each touch a different part of the database.

  • DDL (Data Definition Language): defines structure with CREATE, ALTER and DROP.
  • DML (Data Manipulation Language): moves data with INSERT, UPDATE and DELETE.
  • DQL (Data Query Language): reads data, and it is just SELECT.
  • Constraints: rules like PRIMARY KEY, FOREIGN KEY, NOT NULL and CHECK that keep the data correct.
Watch Out: The most repeated trap is mixing ALTER with UPDATE and DELETE with DROP. ALTER and DROP are DDL, so they reshape the table structure; UPDATE and DELETE are DML, so they only change the rows inside it. Sort the verb into its family first and the answer is automatic.

Because every command belongs to one family, sorting a verb into DDL or DML tells you what it is allowed to touch before you write a single line. The next sections show how this plays out across the functions and queries in the NCERT exercise.

Single-Row Functions vs Aggregate Functions in SQL

The NCERT chapter splits functions into two groups, and Q 1 and Q 2 test the difference directly. A single-row function reads one value per row and returns one result per row, so the row count stays the same. An aggregate function reads a whole column of many rows and returns a single summary value, so it collapses the rows into one.

-- single-row functions: one result per row
SELECT POW(2,3);                 -- 8
SELECT ROUND(342.9234,-1);       -- 340  (negative places round left)
SELECT LENGTH("Informatics Practices");   -- 21  (spaces count)
SELECT UPPER("india");           -- INDIA

-- aggregate functions: one result for the whole column
SELECT SUM(UPrice), AVG(UPrice), COUNT(*) FROM Product;

The quick test is one question: does the function collapse many rows into one? If yes, it is an aggregate (SUM, AVG, MAX, MIN, COUNT); if it keeps the row count, it is single-row (UPPER, ROUND, LENGTH, the date functions). Single-row functions can sit inside a WHERE clause, but aggregates usually need a GROUP BY.

Quick Tip: For SQL string functions, number the characters from 1, not 0. In MID("Informatics",3,4) position 3 is the letter f, so the result is "form". Drawing a tiny numbered grid kills most string-slice mistakes.

Writing SELECT Queries: WHERE, ORDER BY, GROUP BY and IS NULL

Most of the marks in this chapter come from query writing on the MOVIE, TEAM and Product tables. The trick is to read each English phrase and convert it straight into a clause, because board SQL questions are written so the words almost dictate the SQL.

English phrase in the questionSQL clause to write
Display all informationSELECT * FROM t
List the different / unique valuesSELECT DISTINCT col
Calculated as a sum or differencearithmetic with AS alias
Greater than X and less than YWHERE col > X AND col < Y
Either A or BWHERE col IN ('A','B')
Not released yet / no valueWHERE col IS NULL
In descending orderORDER BY col DESC
Total number per groupGROUP BY col with COUNT(*)

The single biggest trap, flagged by most students, is testing for a missing value with =. In Q 3 part (g), the movies "not released yet" have no release date, so you must write WHERE ReleaseDate IS NULL. Writing WHERE ReleaseDate = NULL returns zero rows because nothing ever equals NULL in SQL.

Remember: Use IS NULL and IS NOT NULL to test for missing values, never = NULL. This one rule decides the unreleased-movie part in Q 3 and the no-discount part in Q 8.
SQL SELECT WHERE GROUP BY and aggregate functions for Class 12 Computer Science Chapter 9

CREATE TABLE, Constraints and Foreign Keys in the NCERT Exercise

The DDL questions, Q 4 and Q 6, are where careful answers earn the most. A clean CREATE TABLE answer is built in two passes: choose the data type from the value, then layer the constraints from the rules in the question.

Choosing types and constraints (Q 4)

Whole numbers get INT, short text gets VARCHAR, a calendar date gets DATE. Then every business rule becomes a constraint: "between 1 and 9" becomes a CHECK, "unique identification" becomes the primary key, and "length not less than 10 characters" is met by sizing the column at VARCHAR(10).

CREATE TABLE TEAM (
    TeamID   INT CHECK (TeamID BETWEEN 1 AND 9),
    TeamName VARCHAR(10) NOT NULL,
    PRIMARY KEY (TeamID)          -- table-level primary key
);

Note the wording in Q 4 part (c): a table-level constraint means writing PRIMARY KEY (TeamID) on its own line after the columns. Writing TeamID INT PRIMARY KEY is a column-level constraint and can cost the mark when the question asks for table level.

Foreign keys and referential integrity (Q 6)

A foreign key links a column in a child table to the primary key of a parent table, so a value can enter the child only if it already exists in the parent. This is referential integrity, and it is exactly what fixes the COST table data leak in Q 6.

  • "Can be entered only if it is already there in the other table" means a FOREIGN KEY.
  • "Only if it has a valid name" means a NOT NULL constraint.
  • "Price always greater than zero" means a CHECK (Price > 0).

Tip: Always insert the parent row before the child row. Once a foreign key is in place, inserting into COST before UNIFORM is rejected because there is nothing to reference.

Aggregate Queries and CASE Updates: GROUP BY, COUNT, AVG and Discounts

Q 7 and Q 8 mix aggregate output with conditional updates. The safe method for the aggregate parts is to cluster the rows by the grouping column first, then read the answer off each cluster.

GROUP BY aggregates (Q 7)

Cluster the Product rows by PName once: Washing Powder {120}, Toothpaste {54, 65}, Soap {25, 38}, Shampoo {245}. Then every GROUP BY PName query is a quick scan. The averages are 120, 59.5, 31.5 and 245, and COUNT(DISTINCT PName) is 4, not 6, because it counts different names, not rows.

SELECT PName, AVG(UPrice) FROM Product GROUP BY PName;
SELECT COUNT(DISTINCT PName) FROM Product;     -- 4 different names
SELECT Manufacturer, COUNT(*) AS Total
FROM Product GROUP BY Manufacturer;

CASE updates (Q 8)

A single CASE expression handles all three discount rules in one pass, which is cleaner and safer than three separate UPDATE statements. Bucket the cars by model first, then the rule is automatic: LXI gets 0, VXI gets 10 per cent, everything else gets 12 per cent.

UPDATE INVENTORY
SET Discount = CASE
        WHEN Model = 'LXI' THEN 0
        WHEN Model = 'VXI' THEN 0.10 * Price
        ELSE 0.12 * Price
     END;

For "no discount" in Q 8 part (e), the answer is the cars whose computed Discount is 0, which is only the two LXI cars, so the count is 2. The EECO cars do receive 12 per cent, so they are not counted.

Common Mistakes Students Make in the SQL Chapter

The repeat-offender mistakes in SQL chapter board answers:

  • Using = NULL instead of IS NULL: a comparison to NULL always returns nothing, so use IS NULL for unreleased movies and zero-discount cars.
  • Forgetting that ROUND with a negative place rounds left: ROUND(342.9234,-1) is 340, not 350, because the units digit 2 is below 5.
  • Mixing single-row and aggregate functions: an aggregate collapses rows; if you put it in a plain WHERE without GROUP BY it fails.
  • Returning MAX(Price) for "costliest car": the question asks for the car name, so use ORDER BY Price DESC LIMIT 1 or a subquery, not a bare MAX.
  • Column-level instead of table-level constraint: when the question says table level, write PRIMARY KEY (col) on its own line.

How to Use the SQL NCERT Solutions PDF for Board Prep

The SQL chapter is query-heavy but very pattern-driven. The best approach is two passes: one for the four families and the functions, one for writing queries on the textbook tables by hand.

First pass: families and functions (1.5 hours)

Read the chapter and note the DDL, DML, DQL split and the constraint types. Make a one-line meaning for each single-row and aggregate function so the names stick before you start writing queries.

Second pass: write queries by hand (2 hours)

Work Q 3, Q 5, Q 7 and Q 8 on paper first, mapping each English phrase to a clause. Then open these solutions and check your queries. Pay attention to IS NULL, strict ranges with > and <, and aliasing every computed column, because these specifics decide full marks.

CUET and JEE angle

For students preparing competitive exams, SQL appears in CUET Computer Science and in the database rounds of JEE-level programming tests. Query writing, joins and aggregate functions are exactly the kind of questions those papers reuse, so the work here doubles as competitive prep.

Previous Year Question Trends from the SQL Chapter

The SQL chapter is tested in CBSE board papers mainly through query writing and output questions, with a CREATE TABLE question on constraints. The table below maps the asked question types across recent board papers.

YearQuestion type askedMarks
2025Write SELECT queries with WHERE and ORDER BY on a given table; output of an aggregate4 + 1
2024CREATE TABLE with primary key and constraints; GROUP BY with COUNT3 + 2
2023Difference between DELETE and DROP; output of string and date functions2 + 2
2022Single-row vs aggregate functions; UPDATE with a WHERE condition2 + 2
2021Purpose of GROUP BY and ORDER BY; Cartesian product row count2 + 1

Also Check: The full set of CBSE board paper questions for this chapter is included in the downloadable PDF above, updated for the 2026-27 cycle.

Other Resources for Class 12 Computer Science Chapter 9 SQL

Pair this NCERT Solutions PDF with the matching revision notes, handwritten notes and the official NCERT book chapter. All resources for Class 12 Computer Science Chapter 9 Structured Query Language (SQL) are linked below.

ResourceWhat it coversOpen
NCERT SolutionsStep-by-step answers to all 8 exercise questions, with an Expert Solution for each.You are here
NotesConcept-first revision notes on RDBMS, the four SQL families, functions and constraints.Class 12 Computer Science Chapter 9 Notes
Handwritten NotesScanned-style handwritten pages for last-minute board revision.Class 12 Computer Science Chapter 9 Handwritten Notes
NCERT Book PDFOfficial NCERT Computer Science Chapter 9 SQL textbook in PDF form.Class 12 Computer Science Chapter 9 NCERT Book PDF

NCERT Solutions for Class 12 Computer Science: All Chapters

Related Links: Use the table below to open the NCERT Solutions for the other chapters of Class 12 Computer Science. Every chapter ships with the same step-by-step answer style, full PDF download, and revision FAQ.

All NCERT Solutions for Class 12 Computer Science Chapter 9 SQL with Step-by-Step Solutions

Q 1

Answer the following questions:
a) Define RDBMS. Name any two RDBMS software.
b) What is the purpose of the following clauses in a select statement? (i) ORDER BY (ii) GROUP BY
c) Cite any two differences between Single Row Functions and Aggregate Functions.
d) What do you understand by Cartesian Product?
e) Differentiate between: (i) ALTER and UPDATE (ii) DELETE and DROP
f) Write the function names: (i) day like "Monday" from a date (ii) specified characters from a position of a string (iii) name of the month (iv) your name in capital letters.

Q 2

Write the output produced by the following SQL statements:

a) SELECT POW(2,3);
b) SELECT ROUND(342.9234,-1);
c) SELECT LENGTH("Informatics Practices");
d) SELECT YEAR("1979/11/26"), MONTH("1979/11/26"),
          DAY("1979/11/26"), MONTHNAME("1979/11/26");
e) SELECT LEFT("INDIA",3), RIGHT("Computer Science",4),
          MID("Informatics",3,4), SUBSTR("Practices",3);
Q 3

Consider the MOVIE table (MovieID, MovieName, Category, ReleaseDate, ProductionCost, BusinessCost) and write SQL queries for:
a) Display all information from the Movie table.
b) List MovieID, MovieName and Total_Earning (sum of ProductionCost and BusinessCost).
c) List the different categories of movies.
d) Find NetProfit (BusinessCost minus ProductionCost) per movie.
e) List movies with ProductionCost greater than 10,000 and less than 1,00,000.
f) List movies in the category comedy or action.
g) List movies not released yet.

Q 4

Help the sports teacher: a) Create a database "Sports". b) Create table "TEAM" so TeamID is an integer between 1 and 9 (unique team identity) and TeamName is a string of length not less than 10 characters. c) Using a table-level constraint, make TeamID the primary key. d) Show the structure of TEAM. e) Insert (1, Team Titan), (2, Team Rockers), (3, Team Magnet), (4, Team Hurricane). f) Show the contents using a DML statement. g) Create table MATCH_DETAILS with appropriate data types and constraints and insert the match data.

Q 5

Using the Sports database (TEAM and MATCH_DETAILS), write queries for:
a) MatchID of matches where both teams scored more than 70.
b) MatchID where FirstTeam scored less than 70 but SecondTeam scored more than 70.
c) MatchID and date of matches played by Team 1 and won by it.
d) MatchID of matches played by Team 2 and not won by it.
e) Rename TEAM to T_DATA and rename TeamID, TeamName to T_ID, T_NAME.

Q 6

Wonderful Garments has database SCHOOLUNIFORM with relations UNIFORM (UniformCode primary key) and COST (UCode + Size composite key). Write SQL to fix each anomaly:
a) Also keep handkerchiefs (red, medium) at Rs. 100 each.
b) The query inserting into COST works even when the item is not in UNIFORM. Make a provision so a row enters COST only if the UCode is already in UNIFORM.
c) A new UCode should be assignable only if it has a valid UName.
d) Add a constraint so price is always greater than zero.

Q 7

Consider the Product table (PCode, PName, UPrice, Manufacturer). Write SQL for: a) Create the table with appropriate types and constraints. b) Identify the primary key. c) List PCode, PName, price in descending order of name, then ascending price. d) Add a column Discount. e) Set Discount to 10% of UPrice where UPrice > 100, else 0. f) Increase price by 12% for Dove products. g) Total products per manufacturer. Write the output of: h) SELECT PName, avg(UPrice) FROM Product GROUP BY PName; i) SELECT DISTINCT Manufacturer FROM Product; j) SELECT COUNT(DISTINCT PName) FROM Product; k) SELECT PName, MAX(UPrice), MIN(UPrice) FROM Product GROUP BY PName;

Q 8

Using the CARSHOWROOM database (table INVENTORY with CarId, CarName, Price, Model, YearManufacture, Fueltype), write SQL for:
a) Add a column Discount in INVENTORY.
b) Set discounts: (i) no discount on LXI; (ii) 10% on VXI; (iii) 12% on cars other than LXI and VXI.
c) Display the name of the costliest car with fuel type "Petrol".
d) Average discount and total discount on Baleno cars.
e) Total number of cars having no discount.

NCERT Solutions Class 12 Computer Science Chapter 9 Structured Query Language (SQL) FAQs

Ques. How many questions are there in NCERT Class 12 Computer Science Chapter 9 Structured Query Language (SQL)?

Ans. There are 8 end-of-chapter exercise questions in NCERT Class 12 Computer Science Chapter 9 Structured Query Language (SQL). All 8 are solved with full answers and an Expert Solution in the PDF. The mix is one short-answer block, one output-finding question on functions, and six query-writing questions on the MOVIE, TEAM, MATCH_DETAILS, SCHOOLUNIFORM, Product and CARSHOWROOM tables.

Ques. What is the difference between a single-row function and an aggregate function in SQL?

Ans. A single-row function reads one value per row and returns one result per row, so the row count stays the same. Examples are UPPER, ROUND, LENGTH and the date functions. An aggregate function reads a whole column of many rows and returns a single summary value, so it collapses the rows into one. Examples are SUM, AVG, MAX, MIN and COUNT. The quick test is to ask whether the function collapses many rows into one. If yes, it is an aggregate, and it usually needs a GROUP BY.

Ques. Why should you use IS NULL instead of = NULL in SQL?

Ans. In SQL nothing ever equals NULL, not even NULL itself, because NULL means an unknown or missing value. So a condition like WHERE ReleaseDate = NULL always returns zero rows. To test for a missing value you must use IS NULL, and to test for a present value you use IS NOT NULL. This is exactly why Question 3 part (g), which asks for movies not released yet, uses WHERE ReleaseDate IS NULL, and why the no-discount count in Question 8 uses the same idea.

Ques. What is the difference between DELETE and DROP in SQL?

Ans. DELETE is a DML command that removes selected rows from a table using a WHERE condition, but the empty table and its structure stay in the database, so you can still insert new rows later. DROP is a DDL command that removes the entire table object, including its structure, all its rows and its column names, so the table no longer exists. The simple way to remember it is that DELETE clears data while keeping the container, and DROP destroys the container itself.

Ques. How do you write a table-level primary key in a CREATE TABLE statement?

Ans. A table-level primary key is written as a separate line after all the column definitions, like PRIMARY KEY (TeamID). This is different from a column-level primary key, which is written inline beside the column as TeamID INT PRIMARY KEY. When a board question explicitly says to use a table-level constraint, as in Question 4 part (c), you must use the separate PRIMARY KEY (col) line, because the column-level form can cost the mark even though both make the column unique and not null.

Ques. How many pages is the Class 12 Computer Science SQL NCERT Solutions PDF?

Ans. The Structured Query Language (SQL) NCERT Solutions PDF runs about 22 pages and covers all 8 exercise questions with ready-to-run SQL, output tables, and an Expert Solution for each question. Both Normal and HD versions are available from this page, and both are free to download for the 2026-27 session.

Ques. Is the NCERT Solutions for Class 12 Computer Science Chapter 9 aligned with the 2026-27 syllabus?

Ans. Yes. This page reflects the current 2026-27 CBSE syllabus for Class 12 Computer Science. The Structured Query Language (SQL) chapter is part of the Database Management unit, and every answer follows the NCERT textbook, including the four SQL families, single-row and aggregate functions, and the constraint types. The solutions are useful for the CBSE board exam, and the same SQL skills help with CUET Computer Science and JEE-level database questions.

Ques. What is a Cartesian product in SQL?

Ans. A Cartesian product happens when two tables are written together in the FROM clause with no join condition. SQL then pairs every row of the first table with every row of the second table. If the first table has m rows and the second has n rows, the result has m multiplied by n rows. It is also called a cross join. In the board exam, the most common follow-up is to ask for the number of rows in the result, so always state the m times n row count in your answer.