Default Value for DATETIME column in SQL Server Management Studio 2017

r3dfarce picture r3dfarce · Jul 23, 2018 · Viewed 10.7k times · Source

Is it possible to create a table with a column that has type DATETIME and give it a default value such as CURRENT_TIMESTAMP or GETDATE()? Is there another way to do this?

Screenshot from SSMS 2017

Screenshot

Answer

Andrea picture Andrea · Jul 23, 2018

Define a constraint using TSQL:

ALTER TABLE TableName ADD CONSTRAINT DF_TableName DEFAULT GETDATE() FOR ColumnName