tezvyn:

What is the difference between DDL and DML in SQL?

AI-drafted, machine-checkedSource: Wikipedia: SQLbeginner
WHAT IT TESTS

Your grasp of the schema-versus-data boundary.

ANSWER OUTLINE

DDL shapes schema with CREATE or ALTER; DML handles row-level data with SELECT, INSERT, UPDATE, or DELETE.

RED FLAG

Labeling SELECT as DDL or insisting DDL never affects data.

WHAT THIS TESTS: This question checks whether you can cleanly separate structural operations from data operations, a distinction that matters for locking, transaction boundaries, and access control in production databases. Seniors should show they know that DDL usually implies an implicit commit in many engines and that DML is the day-to-day workload that runs inside explicit transactions.

A GOOD ANSWER COVERS: First, define DDL as the vocabulary that creates, alters, or removes database objects and their rules, with canonical examples being CREATE TABLE, ALTER TABLE, and DROP INDEX. Second, define DML as the vocabulary that reads or changes the rows within those objects, with canonical examples being SELECT, INSERT, UPDATE, and DELETE. Third, add nuance by noting that some commands blur the line, such as TRUNCATE TABLE, which removes all rows like DELETE but resets storage metadata like DDL and typically cannot be rolled back in a standard transaction. Fourth, mention the operational impact: DDL often acquires aggressive locks and may rewrite table structures, while DML generally operates row by row and participates in MVCC and rollback logs.

COMMON WRONG ANSWERS: A red flag is classifying SELECT as DDL simply because it queries the database; it is squarely DML because it manipulates data sets, not schema. Another red flag is claiming that DDL never changes data; in practice, dropping a column destroys data, and some ALTER TABLE operations rewrite every row. A third red flag is stating that all DDL is fully transactional everywhere; in MySQL with MyISAM or in some Oracle DDL contexts, structural changes auto commit and cannot be undone within the same transaction.

LIKELY FOLLOW UPS: An interviewer might ask how PostgreSQL handles transactional DDL versus MySQL, or what happens to running DML when an ALTER TABLE is executed on a busy table. They might also ask where Data Control Language fits, or how TRUNCATE differs from DELETE under the hood in terms of triggers and storage reclamation.

ONE CONCRETE EXAMPLE: Imagine you need to add a new column to a ten million row orders table. The command ALTER TABLE orders ADD COLUMN discount DECIMAL(10,2) is DDL; it changes the schema definition and in many systems will lock the table and rewrite it. After the column exists, the command UPDATE orders SET discount = 0.10 WHERE status = promo is DML; it touches only qualifying rows, runs inside a transaction, and can be rolled back if the application detects an error.

Read the original → en.wikipedia.org

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.