Results 1 to 6 of 6

Thread: trigger script

  1. #1
    Join Date
    May 2002
    Posts
    395

    Unanswered: trigger script

    This is additional info needed for the previous post.

    I'm developing in MS SQL Server 7.0 environment.

    This is the script for the trigger:

    CREATE TRIGGER trgtblBag_data ON tblDelete_Inventory
    FOR DELETE
    AS
    Declare @work_ord_num char;

    SELECT @work_ord_num = work_ord_num
    FROM tblDelete_Inventory

    DELETE tblBag_data
    WHERE @work_ord_num = work_ord_num

    Thanks!

  2. #2
    Join Date
    Jul 2002
    Location
    Village, MD
    Posts
    621

    Re: trigger script

    Originally posted by alicejwz
    This is additional info needed for the previous post.

    I'm developing in MS SQL Server 7.0 environment.

    This is the script for the trigger:

    CREATE TRIGGER trgtblBag_data ON tblDelete_Inventory
    FOR DELETE
    AS
    Declare @work_ord_num char;

    SELECT @work_ord_num = work_ord_num
    FROM tblDelete_Inventory

    DELETE tblBag_data
    WHERE @work_ord_num = work_ord_num

    Thanks!
    Try this:

    CREATE TRIGGER trgtblBag_data ON tblDelete_Inventory
    FOR DELETE
    AS

    DELETE tblBag_data
    WHERE work_ord_num in
    (SELECT work_ord_num
    FROM inserted)

  3. #3
    Join Date
    May 2002
    Posts
    395

    Re: trigger script

    Originally posted by snail
    Try this:

    CREATE TRIGGER trgtblBag_data ON tblDelete_Inventory
    FOR DELETE
    AS

    DELETE tblBag_data
    WHERE work_ord_num in
    (SELECT work_ord_num
    FROM inserted)
    No, it still doesn't work.
    How does trigger works? When an action occurred such as insert a record in tblDelete_Inventory doesn't the trigger script executes?
    No syntax or any kind of error occurred.
    Also, why can't I see the name of trigger in drop down box in triggers properties?

    I appreciate any suggestions or possible solution.

  4. #4
    Join Date
    Jan 2003
    Location
    Massachusetts
    Posts
    5,799
    Provided Answers: 11
    This trigger should not care about inserts or updates, since it is declared "For DELETE".

    As for whether it should show up in a drop down box, Enterprise Manager is notorious for needing the refresh button hit.

    One small correction is that the table "inserted" should be replaced by "deleted". Other than that, the trigger looks like it will work with no problems. Hope this helps.

  5. #5
    Join Date
    Jul 2002
    Location
    Village, MD
    Posts
    621
    Originally posted by MCrowley
    This trigger should not care about inserts or updates, since it is declared "For DELETE".

    As for whether it should show up in a drop down box, Enterprise Manager is notorious for needing the refresh button hit.

    One small correction is that the table "inserted" should be replaced by "deleted". Other than that, the trigger looks like it will work with no problems. Hope this helps.
    Of course it needs to change delete to insert . Stupid copy and paste...

  6. #6
    Join Date
    May 2002
    Posts
    395

    Re: trigger script

    I really need help on this script.

    I need to create a trigger on tblBag_data to add new rows to tblBag_databak, but I'm getting a syntax error.
    If there is more than a record inserted in tblBag_data I want to append the records in tblBag_databak.


    CREATE TRIGGER trgtblBag_databak ON [tblBag_data]
    FOR INSERT
    AS

    If @@trancount > 0
    insert tblBag_databak
    --return
    end

    Thanks for your help.

Posting Permissions

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