Great ๐
Same pattern + real output shown for ALL DML commands — SELECT, INSERT, UPDATE, DELETE.
๐ Base Table (Used for ALL examples)
customers
| customer_id | first_name | last_name | city |
|---|---|---|---|
| 1 | Amit | Kumar | Patna |
| 2 | Neha | Singh | Delhi |
| 3 | Ravi | Verma | Lucknow |
๐งพ Summary Table (Questions)
| No. | DML Command | Question |
|---|---|---|
| 1 | SELECT | Retrieve customer names |
| 2 | INSERT | Add a new customer |
| 3 | UPDATE | Update customer city |
| 4 | DELETE | Delete a customer |
1️⃣ SELECT
Question: Show first name and last name of all customers.
SELECT first_name, last_name
FROM customers;
✅ Output
| first_name | last_name |
|---|---|
| Amit | Kumar |
| Neha | Singh |
| Ravi | Verma |
✔ Retrieves data from table
✔ Does not modify data
2️⃣ INSERT
Question: Add a new customer named Mary Doe from Mumbai.
INSERT INTO customers (first_name, last_name, city)
VALUES ('Mary', 'Doe', 'Mumbai');
✅ Table AFTER INSERT
| customer_id | first_name | last_name | city |
|---|---|---|---|
| 1 | Amit | Kumar | Patna |
| 2 | Neha | Singh | Delhi |
| 3 | Ravi | Verma | Lucknow |
| 4 | Mary | Doe | Mumbai |
✔ Adds new record
✔ Existing records remain unchanged
3️⃣ UPDATE
Question: Update city of customer Ravi to Kanpur.
UPDATE customers
SET city = 'Kanpur'
WHERE first_name = 'Ravi';
✅ Table AFTER UPDATE
| customer_id | first_name | last_name | city |
|---|---|---|---|
| 1 | Amit | Kumar | Patna |
| 2 | Neha | Singh | Delhi |
| 3 | Ravi | Verma | Kanpur |
| 4 | Mary | Doe | Mumbai |
✔ Modifies existing record
✔ WHERE condition is important
4️⃣ DELETE
Question: Delete customer Mary Doe.
DELETE FROM customers
WHERE first_name = 'Mary';
✅ Table AFTER DELETE
| customer_id | first_name | last_name | city |
|---|---|---|---|
| 1 | Amit | Kumar | Patna |
| 2 | Neha | Singh | Delhi |
| 3 | Ravi | Verma | Kanpur |
✔ Removes record permanently
✔ Use WHERE to avoid deleting all rows
๐ง One-Line Memory Trick (DML)
| Command | Meaning |
|---|---|
| SELECT | Read data |
| INSERT | Add data |
| UPDATE | Change data |
| DELETE | Remove data |
⚠️ Exam Trap (Very Important)
DELETE FROM customers;
❌ Deletes ALL records (no WHERE)
If you want next:
DDL commands (CREATE, ALTER, DROP, TRUNCATE)
TCL commands (COMMIT, ROLLBACK, SAVEPOINT)
MCQs with table outputs
Hindi explanation for exams
Just say ๐
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.