Spring Deals - hours only!Up to 70% 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
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 IsActive value to the default and change the path for his photo to imgs/alan3.jpg.

Stuck? Here's a hint!

Use IsActive = DEFAULT in the UPDATE statement.