Why SQL feels like magic in everyday apps

Ever wondered how Netflix knows exactly what show to suggest? That's SQL at work behind the scenes, pulling data from huge tables in a flash.

💡 In Simple Words: SQL is a language that lets you ask a computer to find, add, change, or remove information stored in a table, just like asking a friend to fetch a specific book from a library shelf.

What is SQL?

SQL (Structured Query Language) is a set of commands that talk to a database. Think of a database as a giant spreadsheet where each sheet is called a table. SQL lets you write sentences—called queries—that tell the database what you want.

Three families of SQL commands

  • DDL – Data Definition Language: commands that create or change the shape of tables, like building a new shelf.
  • DML – Data Manipulation Language: commands that work with the data inside tables, like putting books on a shelf or taking them out.
  • DCL – Data Control Language: commands that decide who can read or write, similar to a library card system.

Basic DDL commands

CREATE TABLE makes a new table. Example:

CREATE TABLE Students (
    StudentID INT PRIMARY KEY,
    Name VARCHAR(30),
    Marks INT
);

ALTER TABLE changes an existing table, e.g., adding a new column.

Basic DML commands

These are the ones you’ll see most in exams.

SELECT – fetches data.

SELECT Name, Marks FROM Students WHERE Marks > 80 ORDER BY Marks DESC;

INSERT – adds a new row.

INSERT INTO Students (StudentID, Name, Marks) VALUES (101, 'Anita', 92);

UPDATE – changes existing rows.

UPDATE Students SET Marks = 95 WHERE StudentID = 101;

DELETE – removes rows.

DELETE FROM Students WHERE StudentID = 101;

Quick comparison

Command typeTypical use
DDLCreating or modifying table structures
DMLAdding, reading, updating, deleting data
DCLGranting or revoking user permissions

How a SQL query travels inside the DBMS

graph TD A[Write SQL query] --> B[Send to DBMS] --> C[Parse & Optimize] --> D[Execute on data] --> E[Return result set] --> F[Display to user]

Think of the DBMS (Database Management System) as a kitchen. Your query is the order ticket, the parser is the chef reading the ticket, the optimizer decides the fastest cooking route, and the executor actually cooks the dish before serving it to you.

Exam‑friendly tips

  • Remember the order of clauses in a SELECT statement: SELECT → FROM → WHERE → GROUP BY → HAVING → ORDER BY.
  • Primary key uniquely identifies each row; use PRIMARY KEY when creating a table.
  • Use single quotes for text values in conditions, e.g., WHERE Name = 'Anita'.
  • Practice writing queries on a small sample table – the pattern stays the same no matter how big the data.

📝 Likely Exam Questions

  1. Write a SQL query to list the names of students who scored more than 75 marks, sorted in descending order.
    Answer: SELECT Name FROM Students WHERE Marks > 75 ORDER BY Marks DESC;
  2. Explain the difference between DDL and DML with an example for each.
    Answer: DDL changes the table structure (e.g., CREATE TABLE), while DML works with the data inside the table (e.g., INSERT INTO).
  3. What does the PRIMARY KEY constraint ensure?
    Answer: It guarantees that each row has a unique, non‑null identifier.
  4. Given a table Books(BookID, Title, Author), write a query to delete the book with BookID = 5.
    Answer: DELETE FROM Books WHERE BookID = 5;
  5. Briefly describe the role of the query optimizer in a DBMS.
    Answer: The optimizer rewrites the query into the most efficient execution plan, choosing the fastest way to retrieve the data.
#CBSE#Class 12#Computer Science#SQL#Database