Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Default values
6. Inserting DEFAULT values by omitting columns
How to auto-generate values in a database
Summary

Instruction

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

INSERT INTO Author (Id, FirstName, LastName, Photo, CreateDateTime, IsActive)
VALUES (3, N'Alan', N'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 Server provides a shorter version that we can use:

INSERT INTO Author (Id, FirstName, LastName)
VALUES (3, N'Alan', N'Hillary');

Notice that SQL Server 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 IsActive columns.