Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Modifying table structure
8. Adding data to a column
Adding NOT NULL constraints
Summary

Instruction

Perfect! But what about if we add a new column to a table with existing data? In that case, the values in the new column for all existing rows will be NULL. We can tweak this using an UPDATE statement:

UPDATE flight SET duration_minutes = 60;

The statement above sets the value of duration_minutes to 60 for all rows. You can also add a WHERE clause to set the given value for a subset of rows (or a single row). For instance:

UPDATE flight SET duration = 320 WHERE id = 1;

The code above sets the value of duration to 320 for the row with id equal to 1.

Exercise

Let's update the store table. Set the value of area to 1000 for the store with ID of 1 and to 2300 for the store with ID of 2.

Stuck? Here's a hint!

Type:

UPDATE store
SET area = 1000
WHERE id = 1;

UPDATE store
SET area = 2300
WHERE id = 2;