Problem in Trigger

  • SQL Server Version 7.0

    Table1 contains data as follows

    Sl_No Qty

    ------------------

    1 2

    2 3

    1 6

    3 4

    1 15

    1 20

    Table2 Desc

    Sl_no , Qty

    I wrote a trigger on Table1 for Update , which inserts slno and qty into table2

    I Run a command " update table1 set qty = 20 where sl_no =1 "

    After that when i saw the contents of the table2 , it is showing as below

    Sl_no Qty

    1 20

    instead as below

    Sl_no Qty

    1 20

    1 20

    1 20

    1 20

    This is the problem i am facing.

    Awaiting for valueable guidance

  • Not sure how your trigger looks but I suspect you have an issue with how to hadle multiple updated rows.

    Should depending on other things and considering if you are inserting all changes look something like this.

    CREATE TRIGGER tr_trigname

    FOR UPDATE

    AS

    INSERT INTO Table2 SELECT Sl_No, Qty FROM inserted

    So now table 2 will look like you state but then if you update 1 to 6 Table 2 will look like

    1 20

    1 20

    1 20

    1 20

    1 6

    1 6

    1 6

    1 6

    and so on for each update. If this is not what is expected and you cannot figure the proper way for you needs please post what your results for each change would do to the tables.

    "Don't roll your eyes at me. I will tape them in place." (Teacher on Boston Public)

Viewing 2 posts - 1 through 1 (of 1 total)

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