Why learn SQL in Class 12?
Ever wondered how apps like Instagram pull your friends' photos in a snap? Behind the scenes, a language called SQL talks to the database and fetches the right data. That's what you'll master in CBSE Class 12.
💡 In Simple Words: SQL is like a friendly librarian. You tell it what book (data) you need, and it brings the exact page to you. No need to search through endless shelves yourself.
What is SQL?
SQL stands for Structured Query Language. “Structured” means the data is organized in tables, like a spreadsheet. “Query” is just a fancy word for a question you ask the computer. So, SQL is a language you use to ask questions or give commands to a database.
Basic SQL Commands you must know
Think of these commands as the most common tools in a carpenter’s toolbox.
- SELECT – asks the database to show you data.
- INSERT – puts new rows (records) into a table.
- UPDATE – changes existing data.
- DELETE – removes rows you don’t need.
- CREATE – builds a new database or table.
- DROP – tears down (deletes) a database or table.
Worked example: A simple student table
First, create a database called school and a table named students.
CREATE DATABASE school;
USE school;
CREATE TABLE students (
roll_no INT PRIMARY KEY,
name VARCHAR(30),
class VARCHAR(5),
marks INT
);
Now insert a couple of rows.
INSERT INTO students VALUES (1, 'Aanya', '12A', 88);
INSERT INTO students VALUES (2, 'Rohit', '12B', 74);
Want to see everyone who scored above 80?
SELECT name, marks FROM students WHERE marks > 80;
The result will be a list with Aanya’s name and her marks.
SQL Query Execution Process
When you hit “run” on a query, the database doesn’t just jump straight to the answer. It follows a short pipeline.
Creating, Updating and Deleting Data
Updating a student’s marks is as easy as changing a line in a notebook.
UPDATE students SET marks = 92 WHERE roll_no = 2;
To delete a record you no longer need:
DELETE FROM students WHERE roll_no = 1;
Common SQL Functions
Functions are built‑in shortcuts that do calculations for you.
- COUNT() – counts rows, e.g.,
SELECT COUNT(*) FROM students; - AVG() – finds the average, e.g.,
SELECT AVG(marks) FROM students; - MAX() / MIN() – highest or lowest value.
- SUM() – adds up numbers, handy for total scores.
SQL vs. Other Query Languages
SQL is the most widely taught language for relational databases (tables that relate to each other). Other languages like NoSQL query languages work with document‑oriented or key‑value stores, which are good for big‑data or flexible schemas. For CBSE exams, stick to SQL.
Quick comparison table
| Feature | SQL | NoSQL |
|---|---|---|
| Data model | Tables with rows & columns | Documents, key‑value, graphs |
| Schema | Fixed (defined before inserting) | Flexible (can change anytime) |
| Typical use | Banking, school records | Social media feeds, IoT data |
Tips for CBSE Class 12 Exams
- Remember the order of clauses in a SELECT statement:
SELECT … FROM … WHERE … GROUP BY … HAVING … ORDER BY …. - Primary key uniquely identifies each row; never duplicate it.
- Use single quotes for text values, no quotes for numbers.
- Practice writing queries on paper – the exam won’t give you a computer.
📝 Likely Exam Questions
- Write a SQL query to display the names of all students who scored more than 80 marks.
SELECT name FROM students WHERE marks > 80; - Explain the difference between
DELETEandDROPstatements.DELETEremoves rows but keeps the table structure.DROPremoves the entire table (or database) permanently. - Given a table
employees(emp_id, emp_name, salary), write a query to find the average salary.SELECT AVG(salary) FROM employees; - What does the
WHEREclause do in a SELECT statement?
It filters rows, returning only those that satisfy the given condition. - Sketch the steps a database follows after you submit a SQL query.
Answer should mention parsing, validation, execution plan creation, execution, and returning the result set (refer to the flowchart).
That’s a wrap! Keep practicing these commands and you’ll feel confident tackling any SQL question in your CBSE board exam.