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.
The default date format is determined by the current language setting. You can change the date format by using the SET LANGUAGE and SET DATEFORMAT statements. The ydm format isn't supported for date.
Add a default constraint with the GETDATE() function as value.
ALTER TABLE myTable ADD CONSTRAINT CONSTRAINT_NAME DEFAULT GETDATE() FOR myColumn
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With