Urgent.News

What's breaking now, across thousands of outlets.

Tech

Building vs Running: The DDL & DML Distinction Nobody Explains Simply

Picture opening Sunrise Supermarket. Before you sell a single item, you build the shelves tables for customers, products, orders. That's construction. Once the shelves are up, you run the shop taking orders, updating them, clearing out the cancelled ones. In SQL, these are two different jobs: DDL and DML. What is DDL? DDL stands for Data Definition Language. These are the commands that build and…

Opening a supermarket is akin to setting up a database. Before any sales can occur, shelves, tables, and products must be built – that's construction. Once the infrastructure is in place, the store runs – orders are taken, cancelled ones removed, and the daily business flows smoothly. In the realm of SQL, these two processes are distinctly different: DDL and DML.

DDL stands for Data Definition Language. These commands are responsible for building and shaping the database. They create tables, modify their structure, or even eliminate them completely. Think of DDL as laying the foundation and erecting the walls of a building. On the other hand, DML stands for Data Manipulation Language. These commands work with the data stored within those tables. They add, update, delete, or retrieve records. DML is what happens once the building has been erected and people start moving in.

To differentiate the two, here are the common commands and their functions:

DDL Commands:

- CREATE: This builds a new table.

- ALTER: This changes an existing table's structure.

- DROP: This deletes a table entirely.

DML Commands:

- INSERT: This adds new records.

- UPDATE: This changes existing records.

- DELETE: This removes records.

- SELECT: This reads/retrieves records.

For example, the command CREATE TABLE customers... builds a new table named 'customers'. The ALTER TABLE customers ADD COLUMN loyalty_points... modifies the structure of the 'customers' table by adding a new column. On the other hand, the command INSERT INTO customers... adds a new record into the 'customers' table. Similarly, the UPDATE orders SET status = Delivered... command updates an existing record in the 'orders' table, while the DELETE FROM orders WHERE order_id = 4; command removes a specific record from the 'orders' table. Lastly, the SELECT * FROM orders; command retrieves all records from the 'orders' table.

Understanding the distinction between DDL and DML can significantly simplify the confusion often associated with SQL commands. Once grasped, the difference between building the structure of the database (DDL) and running the business within it (DML) becomes clear.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

More from Wednesday 16 September →