Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add default value of datetime field in SQL Server to a timestamp

I've got a table that collects forms submitted from our website, but for some reason, when they created the table, they didn't put a timestamp in the table. I want it to enter the exact date and time that the record was entered.

I know it's in there somewhere, but I can't seem to find how to set the default value (like in Access, you use getNow() or Now()) but I don't know where to put it.

like image 253
stephmoreland Avatar asked Feb 03 '11 15:02

stephmoreland


People also ask

What is default TIMESTAMP in SQL?

TIMESTAMP has a default of 0 unless defined with the NULL attribute, in which case the default is NULL .


1 Answers

For modifying an existing column in an existing table:

ALTER TABLE YourTable ADD CONSTRAINT DF_YourTable DEFAULT GETDATE() FOR YourColumn 
like image 87
TheQ Avatar answered Oct 05 '22 22:10

TheQ