How do I create an Insert trigger to copy a table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • WayneW
    New Member
    • Nov 2006
    • 9

    How do I create an Insert trigger to copy a table

    HI,

    I need to create a trigger that will

    1.copy all the records of a table to another table in the same database when and entrydate > 31/01/2007.

    2. Delete the contents of the source table

    Can anyone help me
  • aaryan
    New Member
    • Nov 2006
    • 82

    #2
    hi,
    hmm... for the criteria check ie. entrydate > 31/01/2007 you can create a stored procedure with an input parameter and check the criteria before proceeding further.
    if the condition is satisfied give a dummy insert statement on the table which will trigger the instead of trigger.
    your instead of trigger will appear like this.
    create trigger copydel on destination instead of insert
    as
    begin
    insert destination select * from source
    delete source
    end

    hope i am clear and it helps you.

    Comment

    • WayneW
      New Member
      • Nov 2006
      • 9

      #3
      the trigger date is a date field which must then fire the procedure, not a user input option.
      Thanks

      Comment

      • aaryan
        New Member
        • Nov 2006
        • 82

        #4
        hi waynew,
        cd you just explain the problem and your need more clearly, with examples. i am finding it difficult to follow.

        Comment

        Working...