Search notes:

SQL Server: Fill columns values with default values in insert statements

In a create table statement, a column can be declared with the default property which will provide the value for the respective column in insert statements if no value is provided.
In the following example, the column dt is such a default column whose value default to sysdatetime if not provided in the insert statement:
create table tq84_tab_with_default_values (
  id    integer     not null identity,
  txt   varchar(20) not null,
  dt    datetime2   not null default sysdatetime()
);
go

insert into tq84_tab_with_default_values (txt) values ('foo'); waitfor delay '00:00:01';
insert into tq84_tab_with_default_values (txt) values ('bar'); waitfor delay '00:00:01';
insert into tq84_tab_with_default_values (txt) values ('baz');
go

select txt, dt from tq84_tab_with_default_values order by id;
go

drop table tq84_tab_with_default_values;
go
Github repository about-MSSQL, path: /sql/create/table/columns/default-values-sysdatetime.sql

See also

The identity property.

Index