Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Default values
9. Update a column using a DEFAULT value
Summary

Instruction

Very nice! You can also use DEFAULT in an UPDATE statement.

If the column has a set default value, you can update data using the default value of this column. For example:

UPDATE author
SET photo = DEFAULT
WHERE id = 2;

This statement removes the picture from the account of the author whose id = 2. The remaining data doesn't need to change, so we update the row rather than delete it. The photo column has a default value, so we used it to update the row. Now the string 'imgs/no-photo.jpg' will be the photo column value for this author.

Exercise

The author Alan Hillary (id = 3) would like to set the is_active value to the default and change the path for his photo to imgs/alan3.jpg.

Stuck? Here's a hint!

Use is_active = DEFAULT in the UPDATE statement.