With your users table in hand, let's change it. SQL has three statements for DML: INSERT adds rows, UPDATE modifies existing ones, and DELETE removes them. This lesson focuses on the first two.
INSERT a single row
The shape: INSERT INTO <table> (col1, col2, ...) VALUES (val1, val2, ...);
INSERT INTO users (full_name, email, is_active)
VALUES ('Ross Geller', 'ross@example.com', true);
We named three columns out of five. The id is a serial (so Postgres allocates the next integer), and signed_up_at has DEFAULT now() — both get filled in automatically.
Many rows in one statement
VALUES can take a list of tuples, so a single INSERT can carry as many rows as you like. It's faster (one round trip, one transaction) and reads better.
INSERT INTO users (full_name, email, is_active)
VALUES
('Monica Geller', 'monica@example.com', true),
('Chandler Bing', 'chandler@example.com', false);
UPDATE existing rows
The shape: UPDATE <table> SET col = expr WHERE <predicate>;
The WHERE clause is critical — omit it and you'll update every row in the table. Reach for BEGIN; ... ROLLBACK; if you want to dry-run a destructive update before committing.
UPDATE users
SET is_active = true
WHERE email = '';