Groups | Blog | Home
all groups > sql server new users > october 2006 >

sql server new users : SQL Server 2005 - How to record the time of record insertion


Frank
10/9/2006 1:58:51 PM
Ok, I feel like a retard for having to ask this, but...

In SQL Server 2005, I wish to have a column keep track of when that specific
record was created/updated.

Any suggestions?

I thought I could use GETDATE() in the Formula property, but if I do so,
whenever the aspx page loads and displays that coulum, it displays the
CURRENT datetime of my timezone for EACH record... so all the datetime
values are identical. Further, each time the webpage loads, the field is
updated to the current time again for all records.



Thanks in advance

Frank
10/9/2006 2:43:41 PM
Never Mind... I will just add GETDATE() to the insertion statement




[quoted text, click to view]

Hugo Kornelis
10/9/2006 11:39:59 PM
[quoted text, click to view]

Hi Frank,

You should set the default to GETDATE():

CREATE TABLE Test
(Col1 int NOT NULL PRIMARY KEY,
Col2 datetime NOT NULL DEFAULT GETDATE());
INSERT INTO Test (Col1)
VALUES (1);
WAITFOR DELAY '00:00:02';
INSERT INTO Test (Col1)
VALUES (2);
SELECT * FROM Test;
go
DROP TABLE Test;
go


--
AddThis Social Bookmark Button