Skip to content
/Chapter 8 · DML: Measure Twice, Cut Once
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: aSELECT looks at data but never changes it. This chapter introduces DML, Data Manipulation Language, covers 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';
Schema · Garden ShopTable · orders6 columns · 24 rows
Table · orders

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

6 columns · 24 rows
order_id intcustomer_id intorder_date dateshipped_date datestatus textcoupon_code text
Your task

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

SQL Workbench
query.sqlgarden_shop · SQL engine loading
⌘↵ to run
·
Expected answer
  • Columns: order_id, customer_id, status.
  • Rows: 3 pending orders.
  • This preview is the set of rows a later UPDATE would touch.