DML statements are how you read and change the rows inside a table — the commands you'll type the most, by far.
Retrieves records from one or more tables.
SELECT columns FROM table_name;SELECT * FROM Employee;| id | name | salary |
|---|---|---|
| 1 | John | 65000 |
| 2 | Alice | 70000 |
Common Mistake
Using SELECT * in production code instead of naming the columns actually needed.
Gives a column or table a temporary, more readable name for the result set.
SELECT column AS alias FROM table_name;SELECT name AS EmployeeName, salary AS MonthlySalary
FROM Employee;Common Mistake
Referencing an alias inside the same SELECT's WHERE clause, where it isn't yet available.
Adds a new row to a table.
INSERT INTO table_name (columns)
VALUES (values);INSERT INTO Employee (name, department, salary)
VALUES ('John', 'IT', 65000);Common Mistake
Leaving out a required column with no default, causing a constraint error.
Changes the values of existing rows.
UPDATE table_name
SET column = value
WHERE condition;UPDATE Employee
SET salary = 70000
WHERE id = 1;Common Mistake
Running UPDATE without a WHERE clause and rewriting the whole table.
Removes specific rows from a table.
DELETE FROM table_name
WHERE condition;DELETE FROM Employee
WHERE id = 1;Common Mistake
Confusing DELETE (row-level, DML) with DROP or TRUNCATE (table-level, DDL) — see the DDL lesson.
DML is the family you'll reach for constantly once your tables exist. The next lesson covers DCL — the much smaller family that controls who is allowed to run any of these commands at all.