Solved

get date of record insertion

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

785 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