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