QUICK START:HTMLCSSJavaScriptTypeScriptPythonSQLReactNext.jsNode.jsDSASystem DesignDevOpsCybersecurityAI / ML
Beginner 15 min readModule: Module 3: Data Manipulation (INSERT, UPDATE, DELETE)

DML: INSERT, UPDATE, DELETE & UPSERT

Insert rows, update specific records safely with WHERE, delete records, and handle duplicate collisions with UPSERT.

What You Will Learn in This Lesson

  • Inserting single and multiple rows with INSERT INTO
  • Safe updates with UPDATE ... SET ... WHERE id = ...
  • Handling existing collisions with INSERT ... ON CONFLICT DO UPDATE (UPSERT)

Introduction & Core Concept

Data Manipulation Language (DML) commands allow you to insert, modify, and delete rows in your database tables.
WHY DOES THIS MATTER IN THE REAL WORLD?

Running UPDATE or DELETE without a WHERE clause will accidentally overwrite or wipe all rows in the entire table!

Safe INSERT with RETURNING & UPSERT

sql
sql
1
2
3
4
5
INSERT INTO users (id, email, age)
VALUES ('a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11', 'alex@example.com', 25)
ON CONFLICT (email) DO UPDATE
SET age = EXCLUDED.age
RETURNING id, email, created_at;

Line-by-Line Technical Breakdown

1RETURNING clause returns newly mutated values instantly without a second query.

Try It Yourself (Interactive Editor)

Modify the code in real-time and click Run to test live browser output and console logs.

Intelligent Code Runner & Live Sandbox[SQL]
SQL SOURCE EDITOR
Interactive Live Code

Industry Best Practices & Professional Standards

  • Always double-check WHERE clauses before running UPDATE or DELETE queries.

Lesson Summary & Core Takeaways

  • DML manages the lifecycle of data rows inside relational tables.