Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

get date of record insertion

Posted on 2006-06-16
3
Medium Priority
?
275 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

618 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