SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Afrika
    Join Date
    Jul 2004
    Location
    Nigeria
    Posts
    1,737
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    MS SQL Triggers: how do i delete an updated value

    hi,
    I am working with a trigger. that responds to an update value.

    PROBLEM
    Once the table has been updated, i want to be able to delete the value, since

    1. the trigger would insert new values into other tables
    2. The updated table would be of no use.

    Currently i am using this script below, but i am being adviced that using intermediate variables might return errors, esp. If there are more than one row updated

    CREATE TRIGGER [PO_AGREEMENT_UPDATE] ON [dbo].[e_invoice]
    FOR UPDATE
    AS


    IF UPDATE (STATUS)

    declare @order2invoice int
    select @order2invoice = (select invoice_num from inserted where usr = @user)

    begin
    --i have edited the code, but some scripts will be executed here

    delete from e_invoice where invoice_num = @order2invoice

    end


    Any advice
    Thanks
    Afrika

  2. #2
    SitePoint Guru
    Join Date
    Jan 2004
    Location
    Uppsala, sverige
    Posts
    697
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Code:
    CREATE TRIGGER [PO_AGREEMENT_UPDATE] ON [dbo].[e_invoice]
    FOR UPDATE
    AS
    IF UPDATE (STATUS)
    --
    -- 
    --
    delete from e_invoice where invoice_num 
    in (select invoice_num from inserted where usr = @user)

  3. #3
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,635
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Why not just run the insert on the other table then rollback the transaction, rather than deleting?

  4. #4
    Afrika
    Join Date
    Jul 2004
    Location
    Nigeria
    Posts
    1,737
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks for your comment,
    i cant roll back the transaction, 'cos its an invoice table, generated from a shopping basket, i want to be able to delete it once the transaction is through

    cherio !!!
    Afrika


Bookmarks

Posting Permissions

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