Summer Deals - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Default values
6. Inserting DEFAULT values by omitting columns
Summary

Instruction

Very nice! Now, what if you need to add a default value to more than one column? Here's how you can do it:

INSERT INTO author (id, first_name, last_name, photo, create_timestamp, is_active)
VALUES (3, 'Alan', 'Hillary', DEFAULT, DEFAULT, DEFAULT);

Wherever we want the database to insert the default value, we put DEFAULT.

Since we used more than one DEFAULT in this statement, it got quite long! Fortunately, SQL provides a shorter version that we can use:

INSERT INTO author (id, first_name, last_name)
VALUES (3, 'Alan', 'Hillary');

Notice that SQL allows you to omit DEFAULTs in the VALUES list. In the column list, you also skip any columns where you'd put a DEFAULT value. If you have to insert multiple DEFAULT values, it's easier and quicker to omit them, as we did here.

Exercise

Martin Williams (id = 4) registered to join the site on 2018-09-30. Insert his data with default values for the photo and is_active columns.