Why SQL is the Secret Sauce of Modern Apps
Ever wondered how your favourite game stores high scores or how a shopping site remembers what you added to the cart? That's SQL at work, talking to a database behind the scenes.
💡 In Simple Words: SQL (Structured Query Language) is like a friendly waiter who takes your order (the question) and brings back the exact dish (the data) from a huge kitchen (the database). You just tell the waiter what you want, and it does the rest.
What is SQL?
SQL stands for Structured Query Language. Think of it as a special language that lets you ask a database to show, add, change, or delete information. It’s not a programming language like Java; it’s more like a set of commands you give to a librarian.
Key SQL Commands Every Class 12 Student Should Know
Here are the four big verbs you’ll use most often:
- SELECT – asks the database to fetch data, like “show me all students who scored above 90”.
- INSERT – adds a new record, like “add a new book to the library”.
- UPDATE – changes existing data, like “change the price of a product”.
- DELETE – removes data, like “throw away the broken toys”.
Writing Your First SELECT Query
Imagine a table called students with columns roll_no, name, and marks. To see every student’s name and marks, you write:
SELECT name, marks FROM students;
That line tells the database: “Give me the name and marks columns from the students table.”
Adding Data with INSERT
If you want to add a new student, you’d type:
INSERT INTO students (roll_no, name, marks) VALUES (101, 'Aisha', 88);
Think of it as putting a new card into a deck.
Changing Data with UPDATE
Suppose Aisha improves her marks to 92. You’d run:
UPDATE students SET marks = 92 WHERE roll_no = 101;
The WHERE part is crucial; without it, you’d change every row.
Removing Data with DELETE
To delete the record you just added:
DELETE FROM students WHERE roll_no = 101;
SQL Query Building Steps (Flowchart)
Common Data Types in SQL
Just like a spreadsheet has different column types, SQL tables need to know what kind of data each column holds.
- INT – whole numbers (e.g., age, roll number).
- VARCHAR(n) – short text up to n characters (e.g., names).
- DATE – calendar dates.
- FLOAT – numbers with decimals.
Quick Comparison: SELECT vs INSERT vs UPDATE vs DELETE
| Command | Purpose | Typical Syntax |
|---|---|---|
| SELECT | Read data | SELECT col FROM table WHERE condition; |
| INSERT | Add new row | INSERT INTO table (col1, col2) VALUES (val1, val2); |
| UPDATE | Modify existing rows | UPDATE table SET col=val WHERE condition; |
| DELETE | Remove rows | DELETE FROM table WHERE condition; |
Tips for Writing Error‑Free SQL in Exams
- Always end statements with a semicolon (;). It tells the system “that’s the whole command”.
- Capitalize keywords (SELECT, FROM, WHERE) – it makes your answer neat and easier to read.
- Use single quotes for text values and no quotes for numbers.
- Double‑check column names; a tiny typo will cause “column not found” errors.
📝 Likely Exam Questions
- Write an SQL query to display the name and salary of employees earning more than 50,000, sorted by salary descending.
SELECT name, salary FROM employees WHERE salary > 50000 ORDER BY salary DESC; - Insert a new record into the table
bookswith id=10, title='SQL Basics', and price=299.INSERT INTO books (id, title, price) VALUES (10, 'SQL Basics', 299); - Explain the difference between
VARCHARandINTdata types with examples.
Answer:VARCHARstores character strings, like a name “Riya”.INTstores whole numbers, like a roll number 23. - Update the marks of the student whose roll_no is 15 to 78.
UPDATE students SET marks = 78 WHERE roll_no = 15; - What will happen if you omit the
WHEREclause in an UPDATE statement?
Answer: The database will change the specified column for every row in the table, which is usually a disaster.