Results 1 to 6 of 6
  1. #1
    Join Date
    Nov 2002
    Location
    United States (Various Cities and Locations)
    Posts
    4

    Question Unanswered: Triggers For History Writing...

    If I have one table tblData and want to write the data that is being altered by an UPDATE or DELETE statement to a tblHistory table, how would that work with a trigger? What is the code?

    Each table has a simple strData and intPK_ID column in each.

    Thanks for the assist!
    ABH
    ABH

  2. #2
    Join Date
    Nov 2002
    Posts
    23
    place a trigger on tbldata for update, delete and write your insert statement into tblHistory.

  3. #3
    Join Date
    Nov 2002
    Location
    United States (Various Cities and Locations)
    Posts
    4
    Originally posted by criki
    place a trigger on tbldata for update, delete and write your insert statement into tblHistory.
    What I am having an issue with is, how do I reference whatever row is being deleted? In other words, what is the syntax for the INSERT statement. Is it just INSERT * INTO tblHistory? or something close?
    ABH

  4. #4
    Join Date
    Nov 2002
    Posts
    23
    It's been awhile but I think it's
    Select * from inserted

  5. #5
    Join Date
    Jul 2002
    Location
    Glasgow, Scotland
    Posts
    7

    Re: Triggers For History Writing...

    for delete as

    begin

    insert into (strdate, intPK_ID) tblHistory
    select strdate, intPK_ID from deleted

    end

  6. #6
    Join Date
    Jul 2002
    Location
    Glasgow, Scotland
    Posts
    7

    Re: Triggers For History Writing...

    sorry, didn't mean to post the last one.

    for delete as

    begin

    insert into tblHistory (strData, intPK_ID)
    select strData, intPK_ID from deleted

    end

Posting Permissions

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