Simon
Simon

Reputation: 3285

How insert current datetime on insert in SQL Server 2005

I have table which is filled from external application. I need to fill column datetime with current datetime. This column is not filled by insert query provided by external application. Is there some option? Maybe some trigger?

Upvotes: 2

Views: 7592

Answers (3)

StuartLC
StuartLC

Reputation: 107247

You can default your timestamp as follows

CREATE TABLE X
(
...
[TimeStamp] DATETIME DEFAULT(CURRENT_TIMESTAMP)
)

Upvotes: 0

JNK
JNK

Reputation: 65157

ALTER TABLE MyTable
ADD CONSTRAINT [DT_Default]
DEFAULT (GETDATE()) FOR [MyDatetimeField]
GO

Upvotes: 4

Barry Kaye
Barry Kaye

Reputation: 7761

You can set the Default Value or Binding for your date column in SQL Server Mgmt Studio to a function like GETUTCDATE()

Upvotes: 4

Related Questions