Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default Value for DATETIME column in SQL Server Management Studio 2017

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

like image 749
r3dfarce Avatar asked Jul 23 '18 17:07

r3dfarce


People also ask

What is the max value for datetime in SQL Server?

Remarks. The maximum valid date for a SqlDateTime structure is December 31, 9999.


1 Answers

Define a constraint using TSQL:

ALTER TABLE TableName ADD CONSTRAINT DF_TableName DEFAULT GETDATE() FOR ColumnName
like image 123
Andrea Avatar answered Oct 16 '22 19:10

Andrea