Skip to main content
Albero Academy

INSERT, UPDATE, DELETE

Add, change and remove rows — safely.

Data & Schema9 min

So far we've read data; now we change it. INSERT adds rows, UPDATE changes them, DELETE removes them — together the "write" side of SQL (collectively DML, data manipulation language).

INSERT

add rows
INSERT INTO students (name, email, package)
VALUES ('Aanya', 'aanya@x.com', 6.5);
INSERT INTO students (name, package) VALUES -- several at once
('Rohan', 8.0),
('Priya', 7.25);

UPDATE & DELETE

change and remove
UPDATE students SET package = 9.0 WHERE id = 1;
DELETE FROM students WHERE enrolled IS NULL;

Key takeaways

  1. 01INSERT adds rows (one or many); UPDATE changes them; DELETE removes them.
  2. 02Always include a WHERE on UPDATE/DELETE — without it, every row is affected.
  3. 03Preview a risky change by running the same WHERE as a SELECT first.
  4. 04These write operations are collectively DML.

Finished this chapter?

Mark it complete to track your progress through SQL.