Ever wondered how Netflix knows exactly what show you might binge next? That magic starts with a language called SQL.

SQL (pronounced "sequel") is a way to talk to a database. Think of a database as a giant, super‑organized spreadsheet, and SQL as the set of instructions you give to pull out the rows you need.

What is SQL?

SQL stands for Structured Query Language. It’s the standard language used to manage and retrieve data from relational databases (databases that store information in tables linked by relationships). You can think of a table like a spreadsheet tab – rows are records, columns are fields.

Why does CBSE Class 12 care about SQL?

The board wants you to understand how real‑world apps store data. Knowing SQL lets you create, modify, and query databases – a skill that shows up in exams and future tech jobs.

Basic SQL Commands You Must Know

  • SELECT: pick columns you want to see.
  • FROM: tell SQL which table to look in.
  • WHERE: filter rows based on a condition.
  • INSERT: add a new row.
  • UPDATE: change existing data.
  • DELETE: remove rows.

Writing Your First Query

Imagine a table students with columns roll_no, name, marks. To list the names of students scoring above 80, you’d write:

SELECT name FROM students WHERE marks > 80;

SQL reads this like a recipe: first, select the name column, then look from the students table, and finally keep only those rows where marks are greater than 80.

Creating a Table – The DDL Part

DDL (Data Definition Language) commands shape the structure of your database. To create the students table:

CREATE TABLE students (\n    roll_no INT PRIMARY KEY,\n    name VARCHAR(30),\n    marks INT\n);

INT means integer (whole number). VARCHAR(30) means a short text up to 30 characters.

SQL Command Categories – Quick Comparison

CategoryPurposeTypical Commands
DDLDefine or change database structureCREATE, ALTER, DROP
DMLManipulate the data inside tablesINSERT, UPDATE, DELETE, SELECT
DCLControl access to dataGRANT, REVOKE

Step‑by‑Step Flow for Building a Simple SELECT Query

graph TD A[Identify tables] --> B[Choose columns] B --> C[Write SELECT] C --> D[Add FROM clause] D --> E[Add WHERE condition] E --> F[Add ORDER BY if needed] F --> G[Run query]

Common Mistakes to Avoid

  • Missing commas between column names.
  • Using single quotes for column names instead of backticks (or none at all).
  • Forgetting the semicolon at the end – many DB tools need it.
  • Mixing up AND and OR without parentheses, which changes the logic.

Mini Practice: Write the Query

Given a table books(book_id, title, author, price), list all titles by "J.K. Rowling" priced below 500.

SELECT title FROM books WHERE author = 'J.K. Rowling' AND price < 500;

📝 Likely Exam Questions

  1. Define SQL and mention two types of SQL commands.
    SQL is Structured Query Language, used to manage relational databases. Two types are DDL (e.g., CREATE) and DML (e.g., SELECT).
  2. Write an SQL statement to create a table named employees with columns emp_id (integer primary key), emp_name (string up to 40 chars), and salary (integer).
    CREATE TABLE employees (\n    emp_id INT PRIMARY KEY,\n    emp_name VARCHAR(40),\n    salary INT\n);
  3. Given a table sales(sale_id, product, amount), retrieve the product names where amount is greater than 1000, sorted descending.
    SELECT product FROM sales WHERE amount > 1000 ORDER BY amount DESC;
  4. Explain the difference between DELETE and TRUNCATE statements.
    DELETE removes rows one by one and can be rolled back; it can have a WHERE clause. TRUNCATE removes all rows instantly, cannot be filtered, and usually cannot be rolled back.
  5. What does the PRIMARY KEY constraint enforce?
    It ensures each row has a unique, non‑null value in that column, acting like an identifier.
#CBSE#Class 12#SQL#Database#Computer Science