Home Database SQL INSERT, UPDATE, DELETE Explained — Add, Change and Remove Data

SQL INSERT, UPDATE, DELETE Explained — Add, Change and Remove Data

In Plain English 🔥
Think of a database table like a whiteboard in a classroom. INSERT is writing something new on the board. UPDATE is erasing one word and replacing it with another. DELETE is wiping an entire row clean. That's literally it — three actions, one purpose: keeping your data accurate and up to date.
⚡ Quick Answer
Think of a database table like a whiteboard in a classroom. INSERT is writing something new on the board. UPDATE is erasing one word and replacing it with another. DELETE is wiping an entire row clean. That's literally it — three actions, one purpose: keeping your data accurate and up to date.

Every app you've ever used — Instagram, your bank, Spotify — stores data somewhere. When you post a photo, a row gets added to a database. When you change your username, a row gets updated. When you delete a message, a row gets removed. The three SQL commands that make all of that happen are INSERT, UPDATE, and DELETE. They're not optional extras — they're the heartbeat of every live application on the planet.

Before these commands existed, changing stored data was a nightmare. You'd have to manually edit flat files, rewrite entire records, or run custom scripts that broke constantly. SQL solved this by giving developers three clean, declarative commands that tell the database exactly what you want done — and the database figures out how to do it efficiently.

By the end of this article you'll be able to add new records to a database table, modify existing ones safely, and remove rows you no longer need — all without breaking anything. You'll also know the one catastrophic mistake most beginners make with DELETE (and exactly how to avoid it).

Setting the Scene — The Table We'll Work With All Article

Before we touch INSERT, UPDATE, or DELETE, we need a table to work with. Think of a table like a spreadsheet with fixed column names. Every row is one record — one item of data.

We're going to build a simple employees table for a fictional company. It has four columns: an ID, a name, a department, and a salary. This is realistic enough to make the examples meaningful, and simple enough that you won't get lost.

Here's the SQL to create that table from scratch. Don't worry too much about the CREATE TABLE syntax — that's a separate topic. Focus on the column names and what kind of data each one holds. Every example in this article will use this exact table, so the story builds naturally from here.

create_employees_table.sql · SQL
123456789101112
-- Create a fresh database table called 'employees'
-- Think of this as drawing the columns on your whiteboard
CREATE TABLE employees (
    employee_id   INT PRIMARY KEY,       -- A unique number to identify each person
    full_name     VARCHAR(100) NOT NULL, -- The person's full name (can't be blank)
    department    VARCHAR(50),           -- Which team they work in
    salary        DECIMAL(10, 2)         -- Their salary, e.g. 52000.00
);

-- At this point the table exists but has ZERO rows in it
-- It's like a spreadsheet with headings but no data yet
SELECT * FROM employees;
▶ Output
employee_id | full_name | department | salary
------------+-----------+------------+--------
(0 rows)
🔥
Why One Table for the Whole Article?Jumping between different tables in different examples is one of the biggest reasons beginners get confused. By sticking to one table all the way through, you'll see exactly how INSERT fills it, UPDATE changes it, and DELETE clears it — cause and effect, every time.

SQL INSERT — Writing New Rows Into Your Table

INSERT is how data gets born in a database. Every user account, every order, every log entry starts life as an INSERT statement. The syntax is: tell the table which columns you're filling in, then provide the values in the same order.

There are two styles you'll use constantly. The first inserts one row at a time — useful when your app is responding to a single event, like a user signing up. The second inserts multiple rows in one statement — useful when you're loading a batch of records, like seeding test data.

Always name your columns explicitly in the INSERT statement. If you don't, your query will break silently the moment someone adds or reorders a column in the table schema. Naming columns is a small habit that prevents big disasters.

Notice in the code below how each value lines up with its column. The order of values must match the order of columns you declare — the database won't guess. Get one position wrong and you'll store someone's name in the department field.

insert_employees.sql · SQL
1234567891011121314151617181920212223242526
-- ── STYLE 1: Insert one row at a time ──────────────────────────────
-- Syntax: INSERT INTO table_name (col1, col2, ...) VALUES (val1, val2, ...);

INSERT INTO employees (employee_id, full_name, department, salary)
VALUES (1, 'Sarah Mitchell', 'Engineering', 72000.00);
-- Sarah is now in the database. One row added.

INSERT INTO employees (employee_id, full_name, department, salary)
VALUES (2, 'James Okafor', 'Marketing', 55000.00);

INSERT INTO employees (employee_id, full_name, department, salary)
VALUES (3, 'Priya Nair', 'Engineering', 68000.00);


-- ── STYLE 2: Insert multiple rows in ONE statement ──────────────────
-- More efficient for bulk inserts — one trip to the database instead of three

INSERT INTO employees (employee_id, full_name, department, salary)
VALUES
    (4, 'Carlos Mendes',  'HR',          48000.00),  -- Row 1 of batch
    (5, 'Lisa Thornton',  'Engineering', 76000.00),  -- Row 2 of batch
    (6, 'Derek Huang',    'Marketing',   59000.00);  -- Row 3 of batch


-- Check all rows were added successfully
SELECT * FROM employees;
▶ Output
employee_id | full_name | department | salary
------------+-----------------+-------------+-----------
1 | Sarah Mitchell | Engineering | 72000.00
2 | James Okafor | Marketing | 55000.00
3 | Priya Nair | Engineering | 68000.00
4 | Carlos Mendes | HR | 48000.00
5 | Lisa Thornton | Engineering | 76000.00
6 | Derek Huang | Marketing | 59000.00
(6 rows)
⚠️
Pro Tip: Always List Your Column NamesWriting INSERT INTO employees VALUES (1, 'Sarah', ...) without column names is a ticking time bomb. The moment the table schema changes — a new column gets added, columns get reordered — your INSERT breaks or, worse, silently stores data in the wrong column. Always be explicit: INSERT INTO employees (employee_id, full_name, ...) VALUES (...).

SQL UPDATE — Changing Data That Already Exists

UPDATE is for fixing or changing data that's already sitting in your table. A user changed their email address. An employee got promoted to a new department. A price changed. All of those are UPDATE operations.

The anatomy of UPDATE has three parts: the table name, the SET clause (what you're changing), and the WHERE clause (which rows to change). The WHERE clause is not optional in practice — leave it off and you'll update every single row in the table at once. That's the kind of mistake that ends careers on a Friday afternoon.

You can update multiple columns in one statement by separating them with commas in the SET clause. You don't need to run a separate UPDATE for each column — that would be slow and wasteful.

After every UPDATE in production code, it's good practice to immediately run a SELECT with the same WHERE condition to confirm the change landed correctly. Make it a habit.

update_employees.sql · SQL
1234567891011121314151617181920212223242526272829303132333435363738
-- ── UPDATE 1: Change a single column for one specific row ──────────
-- Sarah got a raise! Update her salary.
-- The WHERE clause targets ONLY the row where employee_id = 1

UPDATE employees
SET salary = 80000.00          -- New value for the salary column
WHERE employee_id = 1;         -- Target only Sarah's row (id = 1)

-- Confirm the change
SELECT full_name, salary FROM employees WHERE employee_id = 1;
-- Output: Sarah Mitchell | 80000.00  ✓


-- ── UPDATE 2: Change multiple columns in one statement ──────────────
-- Carlos moved from HR to Engineering AND got a pay bump

UPDATE employees
SET department = 'Engineering', -- Change department
    salary     = 62000.00       -- Change salary at the same time
WHERE employee_id = 4;          -- Target only Carlos's row

-- Confirm the change
SELECT full_name, department, salary FROM employees WHERE employee_id = 4;
-- Output: Carlos Mendes | Engineering | 62000.00  ✓


-- ── UPDATE 3: Update multiple ROWS at once using a condition ────────
-- Give everyone in Marketing a 10% raise
-- WHERE matches TWO rows: James Okafor and Derek Huang

UPDATE employees
SET salary = salary * 1.10     -- Multiply current salary by 1.10 (add 10%)
WHERE department = 'Marketing'; -- Affects ALL rows where department is Marketing

-- Check both Marketing employees updated
SELECT full_name, department, salary
FROM employees
WHERE department = 'Marketing';
▶ Output
-- After UPDATE 1:
full_name | salary
----------------+-----------
Sarah Mitchell | 80000.00

-- After UPDATE 2:
full_name | department | salary
---------------+-------------+-----------
Carlos Mendes | Engineering | 62000.00

-- After UPDATE 3:
full_name | department | salary
--------------+------------+-----------
James Okafor | Marketing | 60500.00
Derek Huang | Marketing | 64900.00
⚠️
Watch Out: UPDATE Without WHERE Hits Every RowIf you write UPDATE employees SET salary = 0 and forget the WHERE clause, every single employee's salary becomes zero — instantly, with no undo button in most databases. Always write your WHERE clause FIRST before running any UPDATE. Some developers write the SELECT version first (SELECT * FROM employees WHERE employee_id = 4) to confirm they're targeting the right rows, then convert it to an UPDATE.

SQL DELETE — Removing Rows You No Longer Need

DELETE removes entire rows from a table. Not a single column — the whole row. If a user deletes their account, their row is gone. If an order is cancelled and you want to purge it, DELETE is the command.

Just like UPDATE, DELETE has a WHERE clause that controls which rows get removed. And just like UPDATE, forgetting WHERE is catastrophic — it deletes everything in the table, leaving an empty shell. The table itself survives, but every single row inside it is gone.

A smart safety habit before running any DELETE is to run a SELECT with the exact same WHERE clause first. If the SELECT returns the rows you expect, you know the DELETE will only touch those rows. Then swap SELECT * for DELETE and run it.

For situations where you want to wipe all rows but keep the table structure, there's a faster command called TRUNCATE — but that's a topic for another day. For targeted, controlled row removal, DELETE with WHERE is your tool.

delete_employees.sql · SQL
1234567891011121314151617181920212223242526272829303132333435
-- ── SAFETY CHECK FIRST: Run SELECT to see what you're about to delete ──
-- Before deleting, ALWAYS confirm you're targeting the right rows

SELECT * FROM employees WHERE employee_id = 2;
-- Output: 2 | James Okafor | Marketing | 60500.00
-- Good — that's the row we want to remove. Now delete it.


-- ── DELETE 1: Remove one specific row ───────────────────────────────
-- James left the company. Remove his record.

DELETE FROM employees
WHERE employee_id = 2;  -- Targets ONLY the row with id = 2

-- Confirm he's gone
SELECT * FROM employees WHERE employee_id = 2;
-- Output: (0 rows) — the row no longer exists


-- ── DELETE 2: Remove multiple rows matching a condition ──────────────
-- The company is closing the HR department entirely
-- (Note: after UPDATE 2 above, Carlos moved to Engineering, so HR is now empty.
--  Let's add a temp row first to demonstrate)

INSERT INTO employees (employee_id, full_name, department, salary)
VALUES (7, 'Angela Foster', 'HR', 47000.00),
       (8, 'Ben Stafford',  'HR', 44000.00);

-- Now delete everyone in HR in one statement
DELETE FROM employees
WHERE department = 'HR';  -- Deletes Angela and Ben in one go


-- ── See the final state of the table after all operations ───────────
SELECT * FROM employees ORDER BY employee_id;
▶ Output
-- After SELECT safety check:
employee_id | full_name | department | salary
------------+--------------+------------+-----------
2 | James Okafor | Marketing | 60500.00

-- After DELETE 1:
(0 rows)

-- Final table state:
employee_id | full_name | department | salary
------------+-----------------+-------------+-----------
1 | Sarah Mitchell | Engineering | 80000.00
3 | Priya Nair | Engineering | 68000.00
4 | Carlos Mendes | Engineering | 62000.00
5 | Lisa Thornton | Engineering | 76000.00
6 | Derek Huang | Marketing | 64900.00
(5 rows)
⚠️
Watch Out: DELETE Without WHERE Empties Your Entire TableDELETE FROM employees with no WHERE clause deletes every row. The table stays, but all data is gone permanently (unless you're inside a transaction you can roll back). The golden rule: never run a DELETE in production without a WHERE clause and a prior SELECT to verify your target. If your database supports transactions, wrap destructive operations in BEGIN / ROLLBACK until you're certain.
AspectINSERTUPDATEDELETE
What it doesAdds new rows to a tableChanges values in existing rowsRemoves existing rows from a table
Requires WHERE?No — always adds a new rowYes — omitting it updates ALL rowsYes — omitting it deletes ALL rows
Affects row count?Increases by number of rows addedNo change — same number of rowsDecreases by number of rows removed
Can target multiple rows?Yes — multi-row VALUES syntaxYes — WHERE can match many rowsYes — WHERE can match many rows
Reversible without transactions?Only with a matching DELETEOnly with another UPDATENot easily — data is gone
Typical real-world triggerNew user signup, new order placedUser updates profile, price changeAccount deletion, record archiving
Syntax keyword orderINSERT INTO ... VALUES ...UPDATE ... SET ... WHERE ...DELETE FROM ... WHERE ...

🎯 Key Takeaways

  • INSERT adds new rows — always name your columns explicitly to avoid silent data corruption when the schema changes.
  • UPDATE changes existing rows — the WHERE clause is not optional in practice. No WHERE means every row in the table gets updated at once.
  • DELETE removes entire rows, not individual columns — and without WHERE it empties the whole table. Run a SELECT with the same WHERE first as a safety check.
  • The SELECT-before-DELETE habit is one of the most valuable practices in database work — it costs 2 seconds and can save you from catastrophic, irreversible data loss.

⚠ Common Mistakes to Avoid

  • Mistake 1: Running DELETE or UPDATE without a WHERE clause — Every row in the table gets affected instantly. A DELETE FROM employees with no WHERE wipes all 6 rows in one second. Fix: Always write your WHERE clause before running the statement. Better yet, run SELECT * FROM employees WHERE [your condition] first — if those are the rows you want, convert it to DELETE FROM employees WHERE [same condition].
  • Mistake 2: Omitting column names in INSERT — Writing INSERT INTO employees VALUES (1, 'Sarah', 'Engineering', 72000.00) looks fine until someone adds a new column to the table or reorders existing ones. Suddenly your values land in the wrong columns with no error. Fix: Always write INSERT INTO employees (employee_id, full_name, department, salary) VALUES (...) — name every column explicitly, every time.
  • Mistake 3: Thinking DELETE removes the table itself — Beginners often confuse DELETE FROM employees (removes rows, keeps table) with DROP TABLE employees (removes the entire table structure and all its data). After a DELETE without WHERE, the table still exists — it's just empty. Fix: Use SELECT COUNT(*) FROM employees after a delete to confirm the table still exists and check how many rows remain. If you want to remove the table entirely, that's DROP TABLE — a separate, much more serious command.

Interview Questions on This Topic

  • QWhat's the difference between DELETE and TRUNCATE in SQL, and when would you choose one over the other?
  • QIf you run UPDATE employees SET salary = 0 and forget the WHERE clause, what happens — and how could you prevent it in a production environment?
  • QCan you INSERT a row with a NULL value for a column defined as NOT NULL? What error would you see, and how would you fix the data model or the insert statement?

Frequently Asked Questions

Can I undo a DELETE or UPDATE in SQL?

It depends on whether you're inside a transaction. If you wrap your statement in BEGIN (or START TRANSACTION) and haven't committed yet, you can run ROLLBACK to undo it completely. But if the statement was committed — or if your database tool auto-commits — the change is permanent with no built-in undo. This is why the SELECT-first habit and using transactions for risky operations are so important.

What's the difference between DELETE FROM employees and DROP TABLE employees?

DELETE FROM employees removes all the rows inside the table but leaves the table structure (columns, constraints, indexes) intact — the table still exists, just empty. DROP TABLE employees removes everything: the rows, the structure, the whole table — gone. Use DELETE when you want to clear data; use DROP TABLE only when you want to eliminate the table itself entirely.

Can an INSERT statement add rows to multiple tables at the same time?

Standard SQL INSERT only targets one table per statement. To insert into multiple tables, you run separate INSERT statements — one per table. Some databases (like Oracle) have an INSERT ALL syntax for multi-table inserts, but this is an advanced, database-specific feature. For beginners, treat INSERT as a one-table-at-a-time operation and you'll stay out of trouble.

🔥
TheCodeForge Editorial Team Verified Author

Written and reviewed by senior developers with real-world experience across enterprise, startup and open-source projects. Every article on TheCodeForge is written to be clear, accurate and genuinely useful — not just SEO filler.

← PreviousSQL CREATE TABLE and Data TypesNext →SQL SELECT Statement
Forged with 🔥 at TheCodeForge.io — Where Developers Are Forged