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
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
UPDATE students SET package = 9.0 WHERE id = 1;DELETE FROM students WHERE enrolled IS NULL;
Key takeaways
- 01INSERT adds rows (one or many); UPDATE changes them; DELETE removes them.
- 02Always include a WHERE on UPDATE/DELETE — without it, every row is affected.
- 03Preview a risky change by running the same WHERE as a SELECT first.
- 04These write operations are collectively DML.
