You could set the default value of the column to be getdate()
i.e. if you were creating the table programmatically you would
CREATE TABLE [dbo].[Table1] (
[ID] [int] NOT NULL ,
[MyDateColumn] [datetime] NOT NULL DEFAULT GETDATE()
) ON [PRIMARY]
GO
Adding a DEFAULT is much better than using a trigger in this scenario. In addition to hmckillop's post, to add a column to an existing table you can use:
Code:
ALTER TABLE Table1
ADD CreateDate datetime NOT NULL CONSTRAINT DF_CreateDate DEFAULT (getdate())
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.