Skip to content
/ Chapter 8 · Changing Data and Tables
Lesson 8.1 · garden_shop
Lesson 8.1

What Is SQL DML?

INSERT, UPDATE, and DELETE change the data itself. The safest habit is to SELECT first.

Everything so far has been read-only: a SELECT looks at data but never changes it. This chapter introduces DML (Data Manipulation Language): the statements that do change it: INSERT, UPDATE, and DELETE.

The workshop rule is measure twice, cut once. Before you change rows, run a SELECT with the same filter so you can see exactly which rows you're about to affect. Everything you change here happens in a private, in-browser copy, so experiment freely.

Pattern
-- always preview before you change
select * from orders where status = 'pending';

-- ...then the UPDATE targets exactly those rows
update orders set status = 'shipped' where status = 'pending';

DML, DDL, and DQL

SQL statements are often sorted into three groups, by what they change:

  • DML changes the rows in a table: INSERT, UPDATE, and DELETE. The table itself stays the same shape.
  • DDL (Data Definition Language) changes the tables themselves: CREATE TABLE, ALTER TABLE, and DROP TABLE. Lessons 8.8 to 8.10 cover them, starting with Lesson 8.8 · Creating a table.
  • DQL (Data Query Language) is the name some courses give SELECT, which reads and changes nothing. Others count it as DML.

The pair that trips people up is DELETE and DROP TABLE. delete from orders is DML: it removes every row and leaves an empty orders table behind. drop table orders is DDL: the table is gone, and every query that reads it now fails.

Schema · Garden Shop Table · orders 6 columns · 24 rows
Table · orders

One row per order. Unshipped orders have a null shipped_date.

6 columns · 24 rows
order_id int customer_id int order_date date shipped_date date status text coupon_code text
Your task

Preview the rows a future change would touch: find every order whose status is 'pending'. Return order_id, customer_id, and status, sorted by order_id.

·

Run your query to inspect the result.

Expected answer
  • Columns: order_id, customer_id, status.
  • Rows: 3 pending orders.
  • This preview is the set of rows a later UPDATE would touch.