Understanding SQL Commands: DDL vs. DML

Photo by fabio on Unsplash

Understanding SQL Commands: DDL vs. DML

Introduction

When working with relational databases, understanding the distinction between Data Definition Language (DDL) and Data Manipulation Language (DML) commands is crucial. DDL and DML are two categories of SQL commands that serve distinct purposes in managing and manipulating a database. In this blog post, we'll delve into each category and provide an overview of the commands within them.

Data Definition Language (DDL) Commands:

  1. CREATE:

    • Used for creating new database objects, such as tables, views, indexes, and databases.
  2. ALTER:

    • Modifies the structure of existing database objects, including adding or dropping columns in a table.
  3. DROP:

    • Deletes existing database objects, such as tables, views, or databases.
  4. TRUNCATE:

    • Removes all records from a table while retaining the table structure.
  5. COMMENT:

    • Adds comments or descriptions to database objects for documentation purposes.

Data Manipulation Language (DML) Commands:

  1. SELECT:

    • Retrieves data from one or more tables based on specified criteria.
  2. INSERT:

    • Adds new records into a table.
  3. UPDATE:

    • Modifies existing records in a table based on specified conditions.
  4. DELETE:

    • Removes records from a table based on specified conditions.
  5. MERGE (in some database systems):

    • Combines multiple operations (INSERT, UPDATE, DELETE) into a single, atomic statement.

Conclusion:

In summary, DDL commands are focused on defining and managing the structure of the database, creating, altering, or dropping objects. On the other hand, DML commands are concerned with manipulating the data stored in the database—retrieving, inserting, updating, or deleting records from tables. A comprehensive understanding of both DDL and DML commands is essential for effective database management and querying.