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.
-- 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
One row per order. Unshipped orders have a null shipped_date.
Preview the rows a future change would touch: find everyorder whose status is 'pending'. Returnorder_id, customer_id, and status, sorted by order_id.
- Columns: order_id, customer_id, status.
- Rows: 3 pending orders.
- This preview is the set of rows a later UPDATE would touch.