DQL vs DDL vs DML vs DCL vs TCL

Categories of commands within Structured Query Language (SQL) used for managing and interacting with relational databases

Quick memory tip: DQL queries data, DDL defines structure, DML manipulates data, DCL controls access, and TCL manages transactions.

Data Query Language (DQL)

DQL commands are used to retrieve data from the database. It is primarily used for querying and extracting information based on specified criteria.

Examples:

SELECT - Retrieve data from database

-- SELECT: Retrieve specific columns with a filter
SELECT VendorID, fare_amount, trip_distance 
FROM staging_taxi_trips
WHERE fare_amount > 50.00
ORDER BY tpep_pickup_datetime DESC;

Data Definition Language (DDL)

DDL commands are used to define, modify, or delete the structure of database objects. They deal with the database schema itself, not the data within it.

Examples:

  • CREATE - Create database objects (tables, indexes, views, etc.)

  • ALTER - Modify existing database objects

  • DROP - Delete database objects

  • TRUNCATE - Remove all records from a table (structure remains)

  • RENAME - Rename database objects


Data Manipulation Language (DML)

DML commands are used to manipulate the actual data stored within the database objects (tables). They allow users to insert, update, or delete data.

Examples:

  • INSERT - Add new records

  • UPDATE - Modify existing records

  • DELETE - Remove records

  • MERGE - Insert or update records based on conditions


Data Control Language (DCL)

These commands control access and permissions to the database and its objects.

Examples:

  • GRANT - Give user access privileges

  • REVOKE - Remove user access privileges


Transaction Control Language (TCL)

TCL commands are used to manage transactions within a database. They ensure data integrity and consistency by controlling the execution of DML operations as a single, atomic unit.

Examples:

  • COMMIT - Save transaction changes permanently

  • ROLLBACK - Undo transaction changes

  • SAVEPOINT - Set a point within a transaction to rollback to

  • SET TRANSACTION - Set transaction properties


Last updated