Data Manipulation Language, or DML, is the part of SQL used to read and change the data stored in tables. Its four main commands are SELECT for reading, INSERT for adding new rows, UPDATE for changing existing rows, and DELETE for removing rows. Although the syntax is simple, careful use of filtering clauses is essential to avoid unintended changes.
The SELECT statement retrieves data from one or more tables. A query like SELECT column1, column2 FROM table_name; returns specific columns, while SELECT * FROM users; returns every column. Rows can be filtered using a WHERE clause, which supports operators such as =, >, LIKE, and IN; for instance, SELECT * FROM users WHERE age > 18; returns only adults. Results can be sorted with ORDER BY, either ascending (ASC) or descending (DESC), and the number of rows returned can be limited with LIMIT, optionally combined with OFFSET for pagination. NULL values require special handling because they are not equal to anything: IS NULL and IS NOT NULL are used for testing, while functions like COALESCE(value, default) and IFNULL(value, default) substitute a fallback when a value is missing.
Adding new data uses the INSERT INTO statement, which can add a single row or multiple rows at once, such as INSERT INTO users (name, age) VALUES ('Alice', 25);. To change existing rows, the UPDATE statement modifies values, always paired with a WHERE clause to avoid rewriting every row in the table, as in UPDATE users SET age = 26 WHERE id = 1;. The DELETE FROM statement removes rows, again with a WHERE clause to target specific records; omitting the WHERE clause deletes every row in the table. Used together, these commands cover the full lifecycle of working with data.