INSERT INTO students (...)
VALUES (...)
ON CONFLICT (student_id)
DO UPDATE SET cgpa = EXCLUDED.cgpa;
MYSQL STYLE
INSERT INTO students (...)
VALUES (...)
ON DUPLICATE KEY UPDATE
cgpa = VALUES(cgpa);
MERGE FAMILY
MERGE INTO target t
USING source s ON (...)
WHEN MATCHED THEN UPDATE ...
WHEN NOT MATCHED THEN INSERT ...;
Choose the conflict key explicitly.Decide which source wins.Protect immutable columns.Test concurrent requests.Do not assume MERGE behavior is identical across products.
06 • OBSERVE THE RESULT
A Successful Statement Still Needs Verification
AFFECTED ROW COUNT1 row updated
Compare with the expected blast radius. Zero or many may expose a stale key or broad predicate.
RETURNED ROWSUPDATE ... RETURNING student_id, cgpa;
PostgreSQL and some other systems can return changed data directly; syntax and support differ.
POST-CONDITION QUERYSELECT ... WHERE student_id = 106;
Confirm final values and related records using an independent read.
AUDIT EVIDENCEwho · when · what · why
Important systems record accountable change evidence without exposing sensitive values unnecessarily.
07 • PREVIEW, APPLY, UNDO
Interactive Data-Change Laboratory
Build a controlled statement, preview its exact row impact and apply it to a temporary classroom dataset. Nothing is sent to a database.
Choose an operation to generate SQL.
CLASSROOM DATASET
students
5 rows
Will change New row Will delete
08 • MAKE THE RELEASE DECISION
DML Safety Decision Laboratory
Choose a situation and decide whether to proceed, revise or stop.
09 • CHECK YOUR UNDERSTANDING
Ten Formative Concept Checks
1. Why list columns explicitly in INSERT?
2. An UPDATE without WHERE normally targets:
3. Best preview before a DELETE?
4. Multi-row INSERT primarily lets one statement:
5. If an UPDATE reports 8,000 rows but 1 was expected:
6. Upsert syntax is:
7. Setting a nullable column to NULL means:
8. A foreign key may make a parent DELETE:
9. RETURNING is useful for:
10. Which is the safest general DML sequence?
Answered correctly: 0 of 10
10 • EXPLAIN & PREPARE
University and Interview Questions
2-MARK QUESTIONS
Define DML.
INSERT versus UPDATE?
What is an affected-row count?
Why is WHERE important?
What is an upsert?
5-MARK / PRACTICAL
Write single- and multi-row INSERT statements.
Plan a safe salary UPDATE.
Explain referential effects of DELETE.
Compare upsert approaches.
INTERVIEW QUESTIONS
How do you prevent mass UPDATE?
How do retries create duplicates?
What would you verify after DML?
When is MERGE risky?
How do constraints affect a batch?
Show the safe DML answer framework
State the intended business change.
Name the target table and columns.
Define the exact row predicate or conflict key.
Preview row identities and count.
Consider constraints, cascades and concurrency.
Use a transaction where appropriate.
Verify affected rows and post-conditions.
Explain recovery if the result differs.
LEVEL 11 SUMMARY
You Can Now Change Data with Evidence
INSERT maps explicit columns to valid values.
UPDATE changes every row matched by its predicate.
DELETE requires preview, dependency review and recovery planning.
Upsert and MERGE syntax and behavior vary by DBMS.
Affected-row counts and returned rows prove impact.
Safe DML follows preview, validate, change and verify.
COURSE CHECKPOINT
Mark this level when you can write INSERT, UPDATE and DELETE statements and explain their exact row impact before execution.