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) afterSELECT.
Quick Comparison of Common SQL Commands
| Command | Purpose | Basic Syntax |
|---|---|---|
| SELECT | Retrieve data | SELECT column1, column2 FROM table_name WHERE condition; |
| INSERT | Add new rows | INSERT INTO table_name (col1, col2) VALUES (val1, val2); |
| UPDATE | Modify existing rows | UPDATE table_name SET col1=val1 WHERE condition; |
| DELETE | Remove rows | DELETE FROM table_name WHERE condition; |
| CREATE | Make a new table | CREATE TABLE table_name (col1 datatype, col2 datatype); |
| DROP | Delete a table | DROP TABLE table_name; |
How a Simple SQL Query Flows
📝 Likely Exam Questions
- Write a SQL query to fetch the names of all students scoring ‘A’.
Answer:SELECT name FROM students WHERE grade='A'; - Show how to insert a new record into the
subjectstable.
Answer:INSERT INTO subjects (sub_id, sub_name, credits) VALUES (201, 'Physics', 4); - Explain the difference between
DELETEandDROP.
Answer:DELETEremoves rows from a table but keeps the table structure;DROPremoves the entire table including its definition. - 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; - What does the asterisk (*) signify in a SELECT statement?
Answer: It means “select all columns” from the specified table.