Automatically Insert A DateTime Stamp On Insert
Here is one I don’t use often and sometimes forget. So I’ll put it out here.
Normally I do my inserts via .NET or a stored proc and so I do my datetime stamps that way. What if I do not want to do that, surely there is a way to do it inside the table. Well, you are right and it is really very easy. In your table design simply set the default value to (getdate()).
I normally use the visual way of creating my tables so I’ll include a screen shot below. To show how it is done in code I will paste that after the image.
ALTER TABLE [dbo].[tblMyTable] ADD CONSTRAINT [DF_tblMyTable_dtImported] DEFAULT (getdate()) FOR [dtImported]