Why SQL feels like magic for every app

Ever wondered how your favourite shopping site knows what products you liked last week? That invisible wizard is SQL, the language that talks to databases.

SQL (Structured Query Language) is the way we ask a database to give us, add, or change data—think of it like texting a librarian to fetch a specific book.

What is SQL?

SQL stands for Structured Query Language. It’s a set of instructions we write to interact with a relational database – a system that stores data in tables, kind of like a spreadsheet where each row is a record and each column is an attribute.

Key SQL Commands You Must Know

  • SELECT – pulls data out of a table.
  • INSERT – adds new rows.
  • UPDATE – changes existing rows.
  • DELETE – removes rows.
  • CREATE – builds a new table or other database object.
  • DROP – destroys a table or object.

Basic SELECT Statement – Your First Query

Imagine a table called students with columns roll_no, name, and grade. To see every student’s name you write:

SELECT name FROM students;

The word SELECT tells the DB “give me”, and FROM tells it which table to look at. You can add WHERE to filter, like WHERE grade='A' to fetch only top‑scorers.

Writing Data with INSERT

To add a new student record:

INSERT INTO students (roll_no, name, grade) VALUES (101, 'Riya', 'B');

Think of it as handing a new index card to the librarian and asking them to file it under the right columns.

Updating and Deleting Records

If Riya improves to an ‘A’, you update:

UPDATE students SET grade='A' WHERE roll_no=101;

To remove a student who transferred out:

DELETE FROM students WHERE roll_no=101;

Both commands need a WHERE clause; otherwise you’d change or erase every row – a classic exam trap!

Creating Tables with CREATE

Before you can store anything, you need a table. Here’s a simple definition:

CREATE TABLE subjects (
    sub_id INT PRIMARY KEY,
    sub_name VARCHAR(30),
    credits INT
);

INT means integer numbers, VARCHAR means a string of characters, and PRIMARY KEY uniquely identifies each row.

SQL Syntax Tips for CBSE Exams

  • Always end a statement with a semicolon (;).
  • Keywords are case‑insensitive, but writing them in uppercase makes your answer neat.
  • Use single quotes for text values, not double quotes.
  • Remember the order: SELECT … FROM … WHERE … ORDER BY …
  • When a question asks for “all columns”, use * (asterisk) after SELECT.

Quick Comparison of Common SQL Commands

CommandPurposeBasic Syntax
SELECTRetrieve dataSELECT column1, column2 FROM table_name WHERE condition;
INSERTAdd new rowsINSERT INTO table_name (col1, col2) VALUES (val1, val2);
UPDATEModify existing rowsUPDATE table_name SET col1=val1 WHERE condition;
DELETERemove rowsDELETE FROM table_name WHERE condition;
CREATEMake a new tableCREATE TABLE table_name (col1 datatype, col2 datatype);
DROPDelete a tableDROP TABLE table_name;

How a Simple SQL Query Flows

graph TD A[Connect to DB] --> B[Write SQL Query] B --> C[Send Query] C --> D[DB Processes] D --> E[Return Result] E --> F[Display Output]

📝 Likely Exam Questions

  1. Write a SQL query to fetch the names of all students scoring ‘A’.
    Answer: SELECT name FROM students WHERE grade='A';
  2. Show how to insert a new record into the subjects table.
    Answer: INSERT INTO subjects (sub_id, sub_name, credits) VALUES (201, 'Physics', 4);
  3. Explain the difference between DELETE and DROP.
    Answer: DELETE removes rows from a table but keeps the table structure; DROP removes the entire table including its definition.
  4. Write a query to update the grade of the student with roll number 45 to ‘B+’.
    Answer: UPDATE students SET grade='B+' WHERE roll_no=45;
  5. What does the asterisk (*) signify in a SELECT statement?
    Answer: It means “select all columns” from the specified table.
#CBSE#Class 12#Computer Science#SQL#Database