Solved

get date of record insertion

Posted on 2006-06-16
3
271 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 50 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

Free Webinar: AWS Backup & DR

Join our upcoming webinar with experts from AWS, CloudBerry Lab, and the Town of Edgartown IT to discuss best practices for simplifying online backup management and cutting costs.

Question has a verified solution.

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

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
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…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

733 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