Last Modified

  • I am working on a project that will require the transfer of thousands of records from one DB to another. I need to add a new column (LastModified) (Date/Time) to capture the last time a record was modified so I can go back and reconcile the data. Assistance with a trigger to do that is much appreciated.

    Best,

  • heres a generic example; if you post your actual table definition, we could tailor the example to your actual table:

    Create Trigger TableName_Update On TableName For Update As

    Update Tb

    Set tb.date_modified = GetDate()

    From TableName Tb

    Join Inserted i on Tb.PKColumn = i.PKColumn

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Very neat! Thanks.

  • my database [sahia] the table [carti] i want to automaticaly change the [datead] field , with the curent date

    when i insert or update a record. I've tried but did not work

  • geidy_killer89 (7/13/2012)


    my database [sahia] the table [carti] i want to automaticaly change the [datead] field , with the curent date

    when i insert or update a record. I've tried but did not work

    Welcome to SQL Server Central !!!

    Please do not post your problems in other threads.

    Create a new thread of your own and post the code of the trigger you are using along with some explanation of what you are trying to do.


    Kingston Dhasian

    How to post data/code on a forum to get the best help - Jeff Moden
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

  • geidy_killer: Thread hijacking issues aside, you may find the information you seek in this forum post: http://www.sqlservercentral.com/Forums/Topic1332707-392-1.aspx

    Look for answers in it from Kingston and me.


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St

  • The problem was with the Delimitator 🙂 now It works... thank u 4 replay

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply