DML, short for data manipulation language, is the subset of SQL that works on the rows stored inside tables rather than on the tables themselves. Its core statements are INSERT, UPDATE, DELETE and MERGE, and most references also place SELECT in this family because it reads the same data. In databases, DML is the everyday language of applications: every order placed, profile edited or record archived ends up as one or more DML statements executed inside a transaction.
The category exists to separate concerns. DDL defines the schema, DCL grants and revokes privileges, and DML changes the content that the schema holds. Understanding where the boundary lies matters in practice, because the categories differ in transaction behavior, locking, logging and permissions.
Statements that make up DML
DML consists of a small set of statements that each perform one kind of change to row data. The SQL standard groups them as SQL-data change statements, and SELECT appears in some classifications as a query statement and in others as a separate data query language (DQL).
The following table summarizes what each statement does and what it typically affects.
| Statement | Purpose | Rows affected | Typical clause |
|---|---|---|---|
| SELECT | Reads and projects data | None changed | WHERE, JOIN, GROUP BY |
| INSERT | Adds new rows | New rows only | VALUES or a subquery |
| UPDATE | Changes column values | Matching rows | SET with WHERE |
| DELETE | Removes rows | Matching rows | WHERE |
| MERGE | Inserts or updates in one pass | Matched and unmatched rows | WHEN MATCHED |
Vendors add extensions on top of this core. PostgreSQL and SQLite support INSERT ... ON CONFLICT, MySQL offers ON DUPLICATE KEY UPDATE, and several engines provide a RETURNING or OUTPUT clause that hands back the changed rows so that the application avoids a second round trip. These variants are often grouped under the UPSERT label.
How the database engine executes a DML statement
A DML statement passes through parsing, optimization and execution, and only the last stage touches storage. The optimizer chooses an access path, such as an index seek or a full scan, to locate the target rows, which is why a modifying statement benefits from the same indexes as a query.
During execution the engine acquires row or page locks, writes the change to the write-ahead log before modifying data pages, and maintains every affected index. Triggers and foreign key checks run as part of the same statement, so a single UPDATE on a parent table can cascade into many hidden changes elsewhere.
- The parser validates syntax and resolves table and column names.
- The optimizer builds a plan for locating the target rows.
- The executor locks rows, logs the change and modifies pages.
- Constraints, triggers and index maintenance run within the statement.
- The change becomes durable and visible to others at COMMIT.
Under multiversion concurrency control (MVCC), used by PostgreSQL, Oracle Database and others, an update writes a new row version instead of overwriting the old one. Readers keep seeing the previous version until the transaction commits, which is the reason writers rarely block readers in those systems.
DML compared with DDL, DCL and TCL
SQL statements fall into four or five functional categories, and DML is the only one that changes stored data values. The distinctions are not merely academic, because they govern rollback behavior and who may run each statement.
| Category | Acts on | Example statements | Transactional behavior |
|---|---|---|---|
| DML | Row data | INSERT, UPDATE, DELETE | Fully rollback-capable |
| DDL | Schema objects | CREATE TABLE, ALTER TABLE | Implicit commit in many engines |
| DCL | Privileges | GRANT, REVOKE | Varies by engine |
| TCL | Transactions | COMMIT, ROLLBACK, SAVEPOINT | Controls the others |
| DQL | Read results | SELECT | Reads within isolation level |
A frequent point of confusion is TRUNCATE TABLE. It removes all rows, which sounds like DML, but most engines classify it as DDL because it deallocates storage instead of deleting rows one by one. As a result it usually fires no row triggers, resets identity counters in some systems and, in Oracle Database and MySQL, cannot be rolled back. PostgreSQL and Microsoft SQL Server, by contrast, allow TRUNCATE inside a transaction.
Transactions, isolation and safe data changes
Every DML statement runs inside a transaction, either an explicit one opened with BEGIN or an implicit one created by autocommit mode. The transaction guarantees the ACID properties: a multi-statement change either succeeds completely or leaves no trace.
The isolation level decides which anomalies concurrent DML can produce. Higher levels prevent more anomalies but increase locking, retries or serialization failures.
| Isolation level | Prevents | Still allows | Cost |
|---|---|---|---|
| Read uncommitted | Nothing significant | Dirty reads | Lowest |
| Read committed | Dirty reads | Lost updates, phantoms | Low |
| Repeatable read | Non-repeatable reads | Phantoms in some engines | Moderate |
| Serializable | All standard anomalies | Serialization failures | Highest |
Safe practice combines explicit transactions with optimistic or pessimistic concurrency control. A version column checked in the WHERE clause detects that another session changed the row first, while SELECT ... FOR UPDATE locks the row before modifying it.
Performance considerations for bulk DML
The cost of DML grows with rows touched, indexes maintained and log volume generated, not just with statement count. A single UPDATE that changes ten million rows can fill the transaction log, hold locks for minutes and trigger lock escalation to a table lock.
The table below lists common symptoms of poorly designed bulk changes and the usual remedies.
| Symptom | Likely cause | Remedy |
|---|---|---|
| Long blocking of other sessions | One huge transaction | Batch in chunks of thousands of rows |
| Slow inserts | Row-by-row round trips | Multi-row VALUES or bulk load |
| Log or undo space exhausted | Massive single update | Commit per batch, monitor log |
| Updates slower than expected | Many secondary indexes | Drop and rebuild indexes for loads |
| Table bloat after updates | Dead row versions under MVCC | Regular VACUUM or equivalent |
For large loads, dedicated paths such as PostgreSQL COPY or SQL Server BULK INSERT are typically an order of magnitude faster than individual INSERT statements, because they minimize parsing and per-row overhead.
Common mistakes and security risks
The most damaging DML error is an UPDATE or DELETE without a WHERE clause, which silently affects every row. Several client tools offer a safe-updates mode that rejects such statements, and experienced administrators run a matching SELECT first to confirm the row count.
- SQL injection arises when user input is concatenated into DML text; parameterized statements prevent it.
- Relying on autocommit during manual fixes removes the chance to roll back a mistake.
- Ignoring the affected-row count hides logic errors in application code.
- Granting broad DELETE privileges violates the principle of least privilege.
- Forgetting triggers and cascades leads to unexpected changes in related tables.
Auditing requirements often add change data capture or audit triggers that record who changed what, which turns DML history into a compliance asset rather than a blind spot.
The short version
Think of a database as a set of filing cabinets. Building the cabinets and labeling the drawers is one job; putting papers in, correcting them, taking them out and reading them is another. DML is the language for that second job: working with the contents, not the furniture.
Because these changes happen constantly, databases wrap them in transactions so that a half-finished change never sticks. The key takeaway is simple: DML changes data, while other parts of SQL change structure or permissions.
Where it makes a difference
An online retailer needs to raise prices by 4 percent for about 1.2 million products in one category while the shop stays open. A developer first runs a SELECT with the planned WHERE condition and confirms the expected row count. The change is then executed as a series of UPDATE statements in batches of 10,000 rows, each in its own short transaction, ordered by primary key.
Because every batch commits within a fraction of a second, customers continue to place orders without noticeable blocking, and the transaction log never grows beyond normal levels. One batch fails on a constraint violation; it rolls back alone, the bad record is fixed, and the batch is rerun. The whole repricing finishes in under twenty minutes with no downtime and a complete, verifiable record of changed rows.