?
Solved

get date of record insertion

Posted on 2006-06-16
3
Medium Priority
?
277 Views
Last Modified: 2012-08-13
Hi,
I have sql server 2005. Clients will connect to a db on this server and insert some records. I want to have a column that will be filled with the date of record insertion.

I don't want to get the client's date (since he may change the date/time on his system), i want to get the server's date and time.

Regards
0
Comment
Question by:bluesand4
3 Comments
 
LVL 1

Accepted Solution

by:
asduth earned 200 total points
ID: 16921720
step 1 - add a new coulmn to your table :

             alter table MyTable add InsertDateTime datetime

step 2 - create a trigger on your table which will insert the timestamp


        create trigger TRIG_MYTable_InsertDateTime
        after insert
        as
        update MYTable set InsertdateTime = getdate() where PK in (select PK from inserted)
0
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 16921755
add a new column to the table
 
alter table Yourtable add CreationTime datetime not null default getdate()


0
 

Author Comment

by:bluesand4
ID: 16922925
Hi,
I have the following trigger:

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO


CREATE TRIGGER dbo.hi
   ON  dbo.tblContract
   AFTER INSERT
AS
BEGIN
      SET NOCOUNT ON;

      update dbo.tblContract set inserted = getdate()
END
GO

the column is called inserted
but i have now a problem: this called will be updated with the current time for all records..... I want to affect only the record having been now created

 
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question