DEFAULT is often used for date and time columns, and a very common situation is to use the current date and time for the default value. In SQL Server, you use the function
GETDATE() to get the current date and time.
CreateDateTime column of the
Author table has a default value of
GETDATE(). This statement
INSERT INTO Author (Id, LastName, Photo, CreateDateTime)
VALUES (7, N'Smith', N'imgs/Smith2.jpg', DEFAULT);
inserts a row with the
CreateDateTime column with the current date and time (i.e., the date and time of when the record was inserted). Here is the result:
Notice that the first name is not given in this query. The value for
NULL because there is no
DEFAULT value for this column.