Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2004

    Arrow Unanswered: SQL Server Date/Time Question

    I have been searching the net to see how to do this. I'm a noobie to DB's and I may have missed it. OK I have a Customer table and what I want to do is have a column with the date and time that the customer was added to the database ( i.e. Customer Since ) also last time that record was edited. Possible??

    Thanks in advanced
    Brad Nichols

  2. #2
    Join Date
    Feb 2004
    One option is to create a insert-trigger that sets a datetimestamp on inserting a new record. An update-trigger could do the update of a lastedit-field. See BOL (Books Online) for 'TRIGGER'. You can download the latest BOL from
    Last edited by Kaiowas; 10-22-04 at 04:37.

  3. #3
    Join Date
    Jun 2004
    I couldn't make much out of the BOL on this matter. Could you get me started by giving me an example of the trigger and how and when to execute it?

  4. #4
    Join Date
    Jan 2004
    In a large office with bad lighting
    Try this as a place to start

    given the schema

    CREATE TABLE [dbo].[Clients] (
    [ClientID] [int] NOT NULL ,
    [ClientName] [varchar] (30) null
    [ClientStartDate] [datetime] null

    this could be a trigger to ensure the ClientStartDate is populated when one or more new rows are added

    CREATE TRIGGER [trgClient_New]
    UPDATE Clients
    set ClientStartDate = getdate()
    from Clients, inserted
    where inserted.ClientID = inserted.ClientID

    This trigger will fire only when a row or rows are inserted. Inserted is a special table used by triggers and will be populated only when rows are inserted or updated (back to BOL to read more about these tables )

    play with it and see what happens!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts