Best April deals - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Default values
9. Update a column using a DEFAULT value
How to auto-generate values in a database

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 for that 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 'No picture yet' will be the photo column value for this author.

Exercise

The author Olivier Malley (id = 12) would like to set his is_active value to the default and change the path for his photo to 'imgs/olivier3.jpg'.

Stuck? Here's a hint!

Use is_active = DEFAULT in the UPDATE statement.