<aside> ✏️ DML commands work with the data inside tables: INSERT, UPDATE, DELETE.
</aside>
-- Insert multiple rows
INSERT INTO customers (id, first_name, country, score)
VALUES
(6, 'Anna', 'USA', NULL),
(7, 'Sam', NULL, 100)
-- Insert a single row
INSERT INTO customers (id, first_name, country, score)
VALUES (8, 'Max', 'USA', 368)
-- Insert without specifying columns (not recommended)
INSERT INTO customers
VALUES (9, 'Andreas', 'Germany', NULL)
-- Insert only specific columns (others will be NULL/default)
INSERT INTO customers (id, first_name)
VALUES (10, 'Sahra')
INSERT INTO persons (id, person_name, birth_date, phone)
SELECT
id,
first_name,
NULL,
'Unknown'
FROM customers
Always use WHERE to avoid updating all rows accidentally.
-- Update a single customer's score
UPDATE customers
SET score = 0
WHERE id = 6
-- Update multiple columns at once
UPDATE customers
SET score = 0,
country = 'UK'
WHERE id = 10
-- Update all rows where score IS NULL
UPDATE customers
SET score = 0
WHERE score IS NULL
<aside> ⚠️ Without WHERE, UPDATE affects ALL rows in the table!
</aside>
-- Delete specific rows
DELETE FROM customers
WHERE id > 5
-- Delete all rows (keep the table structure)
DELETE FROM persons
-- Faster way to delete all rows (cannot be rolled back)
TRUNCATE TABLE persons
<aside> 💡 TRUNCATE is faster than DELETE for clearing all rows but cannot be rolled back in most databases.
</aside>