Data Manipulation Language (DML) Commands

Great ๐Ÿ‘
Same pattern + real output shown for ALL DML commandsSELECT, INSERT, UPDATE, DELETE.


๐Ÿ“˜ Base Table (Used for ALL examples)

customers

customer_idfirst_namelast_namecity
1AmitKumarPatna
2NehaSinghDelhi
3RaviVermaLucknow

๐Ÿงพ Summary Table (Questions)

No.DML CommandQuestion
1SELECTRetrieve customer names
2INSERTAdd a new customer
3UPDATEUpdate customer city
4DELETEDelete a customer

1️⃣ SELECT

Question: Show first name and last name of all customers.

SELECT first_name, last_name
FROM customers;

✅ Output

first_namelast_name
AmitKumar
NehaSingh
RaviVerma

✔ 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_idfirst_namelast_namecity
1AmitKumarPatna
2NehaSinghDelhi
3RaviVermaLucknow
4MaryDoeMumbai

✔ 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_idfirst_namelast_namecity
1AmitKumarPatna
2NehaSinghDelhi
3RaviVermaKanpur
4MaryDoeMumbai

✔ 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_idfirst_namelast_namecity
1AmitKumarPatna
2NehaSinghDelhi
3RaviVermaKanpur

✔ Removes record permanently
✔ Use WHERE to avoid deleting all rows


๐Ÿง  One-Line Memory Trick (DML)

CommandMeaning
SELECTRead data
INSERTAdd data
UPDATEChange data
DELETERemove 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.