CBSE Class 12 Computer Science Chapter 12: Structured Query Language (SQL) NCERT Solutions
This chapter provides essential NCERT Solutions for Class 12 Computer Science, focusing on Structured Query Language (SQL). Students will learn to differentiate between DDL (Data Definition Language) and DML (Data Manipulation Language) commands, understanding the distinct purposes of commands like DELETE and DROP TABLE. The solutions explain the utility of wildcard characters (%) and (_) in pattern matching with the LIKE operator, crucial for efficient data retrieval. Furthermore, students will practice using ALTER TABLE commands to modify existing table structures, such as adding new columns with specified data types and sizes. The chapter also covers practical SQL query writing for various scenarios, including removing rows while preserving table structure and displaying specific data based on conditions. These solutions are designed to help students grasp fundamental SQL concepts and prepare effectively for their examinations.
Quick info
| Board | CBSE |
|---|---|
| Class | Class 12 |
| Subject | Computer Science |
| Session | 2026 |
| Language | English |
| Type | NCERT Solutions |
| Chapter | 12. Structured Query Language |
Chapter summary
Chapter 12, Structured Query Language (SQL), offers comprehensive NCERT Solutions for Class 12 Computer Science. It covers fundamental SQL commands, including DDL commands like DROP TABLE for removing table structures and DML commands like DELETE for removing data. The solutions explain the use of wildcards (%) and (_) for pattern matching with the LIKE operator and demonstrate how to alter table structures using the ALTER TABLE command to add columns. Practical examples of writing SQL queries for data manipulation and retrieval are provided, reinforcing concepts for students.
Learning outcomes
- Understand the difference between DELETE and DROP TABLE commands.
- Explain the functionality of wildcard characters (%) and (_).
- Apply ALTER TABLE command to add new columns to existing tables.
- Write SQL queries to remove all rows from a table while maintaining its structure.
- Interpret and execute SQL queries involving wildcards and table modifications.
- Analyze and predict the output of given SQL queries on provided table data.
Topics covered
Paper topics
- Structured Query Language (SQL)
- Data Definition Language (DDL)
- Data Manipulation Language (DML)
- DELETE Command
- DROP TABLE Command
- Wildcard Characters
- LIKE Operator
- ALTER TABLE Command
- Adding Columns
- SQL Query Execution
- Table Structure Modification
- Pattern Matching in SQL
Important topics
- DELETE vs DROP TABLE
- Wildcard usage with LIKE
- ALTER TABLE syntax for adding columns
- Understanding SQL query outputs
- DML vs DDL commands
PDF preview
Read page by page below. PDF is streamed from the official NCERT website — no download button on this page.
Questions and Solutions
Question 1
The `DELETE` command is a Data Manipulation Language (DML) command used to remove one or more rows from a table. If used without a `WHERE` clause, it removes all rows but leaves the table structure intact. The `DROP TABLE` command, on the other hand, is a Data Definition Language (DDL) command that completely removes the table's structure, including all its data and indexes, from the database.
Question 2
Wildcard characters are used in SQL with the `LIKE` operator to search for values that match a specified pattern within a column. They allow for flexible pattern matching when the exact value is unknown. The two primary wildcard operators are:
%: Represents zero, one, or multiple characters._: Represents a single character.
Question 3
To add a new column to an existing table, the `ALTER TABLE` command is used. The specific command to add the `total_price` column to the `product` table is:
Question 4
The `ALTER TABLE` command is used to add a new column to an existing table. To add the `price` column with the specified data type to the `customer` table, the following command should be used:
Question 5
To remove all rows from a table while preserving its structure, the `DELETE` command is used. The specific command to remove all data from the `BANK` table is:
Question 6
The problem with Sonal's query is the incorrect use of wildcard characters. The characters `$` and `?` are not standard SQL wildcards. The correct wildcards to use are `_` for a single character and `%` for zero or more characters. To find names where the third character is '0', we need two characters before '0' and any characters after it. The corrected query is:
Question 7
- Select Designation, Count(*) From Admin Group By Designation Having Count(*) <2;
- SELECT max (EXPERIENCE) FROM SCHOOL;
- SELECT TEACHERNAME FROM SCHOOL WHERE EXPERIENCE >12 ORDER BY TEACHER NAME;
- SELECT COUNT (*), GENDER FROM ADMIN GROUP BY GENDER;
Table: SCHOOL
| CODE | TEACHER | SUBJECT | DOJ | PERIODS | EXPERIENCE |
| 1001 | RAVI SHANKAR | ENGLISH | 12/3/2000 | 24 | 10 |
| 1009 | PRIYA RAI | PHYSICS | 03/09/1998 | 26 | 12 |
| 1203 | LIS ANAND | ENGLISH | 09/04/2000 | 27 | 5 |
| 1045 | YASHRAJ | MATHS | 24/8/2000 | 24 | 15 |
| 1123 | GANAN | PHYSICS | 16/7/1999 | 28 | 3 |
| 1167 | HARISHB | CHEMISTRY | 19/10/1999 | 27 | 5 |
| 1215 | UMESH | PHYSICS | 11/05/1998 | 22 | 16 |
TABLE: ADMIN
| CODE | GENDER | DESIGNATION |
| 1001 | MALE | VICE PRINCIPAL |
| 1009 | FEMALE | COORDINATOR |
-
Query: Select Designation, Count(*) From Admin Group By Designation Having Count(*) <2;
Explanation: This query counts the number of entries for each designation in the `Admin` table and then filters to show only those designations that appear less than 2 times. In the given `Admin` table, 'VICE PRINCIPAL' appears once and 'COORDINATOR' appears once. Both counts are less than 2. Output:
DESIGNATION COUNT(*) VICE PRINCIPAL 1 COORDINATOR 1
-
Query: SELECT max (EXPERIENCE) FROM SCHOOL;
Explanation: This query finds the maximum value in the `EXPERIENCE` column of the `SCHOOL` table. Looking at the `EXPERIENCE` column (10, 12, 5, 15, 3, 5, 16), the highest value is 16. Output:
MAX(EXPERIENCE) 16
-
Query: SELECT TEACHERNAME FROM SCHOOL WHERE EXPERIENCE >12 ORDER BY TEACHER NAME;
Explanation: This query selects the names of teachers from the `SCHOOL` table where their `EXPERIENCE` is greater than 12. The teachers with experience greater than 12 are YASHRAJ (15) and UMESH (16). The results are then ordered alphabetically by teacher name. Output:
TEACHERNAME UMESH YASHRAJ
-
Query: SELECT COUNT (*), GENDER FROM ADMIN GROUP BY GENDER;
Explanation: This query counts the number of records for each gender present in the `Admin` table. There is one entry for 'MALE' and one entry for 'FEMALE'. Output:
GENDER COUNT(*) MALE 1 FEMALE 1
Common mistakes
- Confusing DELETE (removes data) with DROP TABLE (removes structure).
- Incorrect usage of wildcard characters in LIKE clauses.
- Syntax errors when using ALTER TABLE to add columns.
- Not specifying conditions in DELETE statements, leading to unintended data removal.
Revision tips
- Focus on the distinction between DDL and DML commands.
- Practice writing queries using wildcards for pattern matching.
- Review the syntax for altering table structures, especially adding columns.
- Work through all example queries to understand their output.
- Understand the impact of commands like DELETE and DROP TABLE on table data and structure.
Practice MCQs
Q1. Which SQL command is used to remove all rows from a table but keep the table structure intact?
Explanation: The DELETE FROM command removes all rows from a table without affecting its structure. DROP TABLE removes the entire table, and TRUNCATE TABLE also removes all rows but is a DDL command.
Q2. What does the wildcard character '%' represent in an SQL LIKE clause?
Explanation: The '%' wildcard in SQL represents any sequence of zero, one, or multiple characters, making it useful for pattern matching.
Q3. Which command is used to add a new column to an existing table?
Explanation: The ALTER TABLE command is used to modify the structure of an existing table, including adding, deleting, or modifying columns.
Q4. If a query needs to find names where '0' is the third character, which pattern is correct?
Explanation: The pattern '__0%' correctly uses two single-character wildcards ('_') followed by '0' and then any number of characters ('%') to match the requirement.
Q5. Which type of SQL command is DROP TABLE?
Explanation: DROP TABLE is a Data Definition Language (DDL) command because it defines or modifies the structure of database objects.
Frequently asked questions
What is the main difference between DELETE and DROP TABLE in SQL?
The DELETE command is a DML command used to remove rows from a table, optionally based on a condition, while keeping the table structure. The DROP TABLE command is a DDL command that removes the entire table, including its structure and all data.
How are wildcards used in SQL?
Wildcards like '%' (matches zero or more characters) and '_' (matches a single character) are used with the LIKE operator in SQL to search for specific patterns within string data in a column.
Which SQL command allows modification of an existing table's structure?
The ALTER TABLE command is used to modify the structure of an existing table. This includes adding new columns, deleting columns, or modifying existing column properties.
What is the purpose of the command 'DELETE FROM BANK'?
The command 'DELETE FROM BANK' is used to remove all the records (rows) from the table named 'BANK' without deleting the table itself or altering its structure.
What is the correct way to add a column named 'price' with a numeric data type (10 digits total, 2 after decimal) to a table named 'customer'?
The correct SQL command to add this column is: ALTER TABLE customer ADD price numeric(10,2);
Why might a query like 'Select name from teacher where name = "$$0?"' fail to produce results?
The query likely fails because it uses incorrect wildcards. The standard SQL wildcards for pattern matching are '%' and '_'. A correct query to find names with '0' as the third character would use LIKE '_ _ 0%'.
Content reviewed by the NCERT Help team. Editorial Team and update policy
NCERT Solutions PDF PDF on NCERT Help. URL unchanged for search indexing.