Is there a way to set the default value of a column to DateTime.Now
in Sql Server?
Example:
table Event
Id int (auto-increment) not null
Description nvarchar(50) not null
Date datetime not null
The line:
Insert into Event(Description) values('teste');
should insert a row and the Date value should be the current date.
Table creation Syntax can be like:
Insertion query syntax can be like:
Select Table Column Name where you want to get default value of Current date
Alter Table Query
Add a default constraint with the GETDATE() function as value.
Right click on the table and click on Design,then click on column that you want to set default value.
Then in bottom of page in column properties set Default value or binding to : 'getdate()'
You can use:
Also, you can change your table so that 'Date' has a default, "GETDATE()"