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 DEFAULT
s 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.