DBMS Languages

DBMS Languages List: DDL DML DCL and TCL

Learn the main DBMS languages: DDL for structure, DML for rows, DCL for permissions and TCL for transactions, with SQL examples and common beginner pitfalls.

On this page
  1. The short answer
  2. DDL: defining the structure
  3. DML: reading and changing rows
  4. DQL: where SELECT fits
  5. DCL: controlling access
  6. TCL: grouping changes into transactions
  7. Pitfalls to watch for
  8. Query languages outside SQL
  9. Where to start

A DBMS, or database management system, is the software that stores data and lets you read and change it. Its languages are usually sorted into four groups: DDL, DML, DCL and TCL. In relational systems, those groups are made of SQL commands. This DBMS languages list explains what each group does, with examples and a few pitfalls to watch for.

The short answer

  • DDL (Data Definition Language) defines and changes structures such as tables. Typical commands: CREATE, ALTER and DROP.
  • DML (Data Manipulation Language) adds, changes and removes rows. Typical commands: INSERT, UPDATE and DELETE.
  • DCL (Data Control Language) grants and revokes permissions. Typical commands: GRANT and REVOKE.
  • TCL (Transaction Control Language) manages transactions. Typical commands: COMMIT, ROLLBACK and SAVEPOINT.

These groups come from textbooks and vendor manuals rather than one official list, so a command can be filed under a different group depending on the source. Use the grouping as a guide, and check your product’s documentation when it matters.

DDL: defining the structure

DDL statements create and change the objects that hold data, such as databases, tables, indexes and views. Here is a simple example:

CREATE TABLE customers (
    customer_id INT PRIMARY KEY,
    email VARCHAR(255) NOT NULL
);

The PRIMARY KEY in that example is a constraint. For how keys link tables together, see what is a pk and fk.

ALTER TABLE changes an existing table, such as by adding a column. DROP TABLE removes the table along with its data. TRUNCATE TABLE removes every row but keeps the table definition.

TRUNCATE is a good example of why the groups can be fuzzy. It removes data rather than changing structure, yet MySQL’s documentation lists it as DDL, and some textbooks file it under DML.

DML: reading and changing rows

DML statements work with the rows inside tables.

  • INSERT adds new rows.
  • UPDATE changes existing rows. Without a WHERE clause, it changes every row in the table.
  • DELETE removes rows. Without a WHERE clause, it removes every row.
  • MERGE combines inserting and updating based on a matching condition. Many systems support it, but not all, so check the syntax for your product.
UPDATE customers
SET email = 'sample@example.com'
WHERE customer_id = 1;

Forgetting the WHERE clause is a common mistake. Before you run an UPDATE or DELETE on real data, try the same WHERE condition in a SELECT to see which rows it matches. For the basics of adding rows, see what is an insert statement.

DQL: where SELECT fits

SELECT reads data without changing it. Some references treat it as its own group, DQL (Data Query Language), while others file it under DML. Either way, it’s probably the command you will use most often.

DCL: controlling access

DCL statements control who can do what with the data.

  • GRANT gives a user or role a permission, such as reading a table.
  • REVOKE removes a permission that was given earlier.
GRANT SELECT ON customers TO report_user;

Account and permission syntax varies between products, so check your manual before running these statements on a live system.

TCL: grouping changes into transactions

A transaction groups several statements so they succeed or fail together. TCL commands control those groups.

  • START TRANSACTION (or BEGIN, depending on the product) opens a transaction.
  • COMMIT saves the changes made in the transaction.
  • ROLLBACK undoes the changes made since the transaction began.
  • SAVEPOINT marks a point inside a transaction that you can roll back to.
START TRANSACTION;
UPDATE accounts SET balance = balance - 100 WHERE account_id = 1;
UPDATE accounts SET balance = balance + 100 WHERE account_id = 2;
COMMIT;

If something goes wrong before COMMIT, a ROLLBACK undoes both updates.

Transactions also raise questions about concurrency, since other sessions may read data while a transaction is open. Isolation levels control which of these effects are allowed. For the basics of one such effect, see what is dirty read in dbms.

Pitfalls to watch for

  • MySQL commits some statements implicitly. Many DDL statements, including CREATE TABLE and TRUNCATE TABLE, end any open transaction first, as if you had issued COMMIT. A later ROLLBACK won’t undo the INSERT or UPDATE statements that ran before them.
  • Undoing deletes is limited. Recovering rows after a DELETE, DROP or TRUNCATE usually depends on backups or logs. For one product’s approach, see how to recover deleted data from sql server database.
  • Dialects differ. T-SQL (SQL Server), PL/SQL (Oracle) and PL/pgSQL (PostgreSQL) each extend SQL with their own features, so code often needs changes to move between products.
  • Not every system has every group. SQLite, for example, has no user accounts, so it has no GRANT or REVOKE.

Query languages outside SQL

Not every database uses SQL. MongoDB uses a JSON-style query syntax, Neo4j uses Cypher for graph data, and many RDF triple stores use SPARQL. These languages don’t map neatly onto the four SQL groups.

Where to start

If you’re new to this, learn SELECT, INSERT, UPDATE and DELETE on a small test database first. Then add CREATE TABLE and transactions. Practice on a copy of real data, not the live system.

Keep exploring

Guides from other topics

All topics →