Trigger question

thudangdichoichu 21 Reputation points

I have 2 trigger, one is for insert and another for delete..

but when i run delete query, an error occurred : A cursor with the name 'x' does not exist.
while x is insert trigger cursor name !

here is trigger for deleted

Can anyone explain for me, thanks

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,111 questions
0 comments No comments
{count} votes

1 additional answer

Sort by: Most helpful
  1. Erland Sommarskog 103.9K Reputation points MVP

    Note that in the DELETE trigger, the FETCH statement is missing at the end of the loop, so if you delete more then one row, the trigger will run forever.

    But it is complete insanity to have a cursor here. I don't know your details, but this is my guess how the DELETE trigger should look like:

    CREATE TRIGGER dbo.hyudon ON dbo.dothang AS
    UPDATE stock
    SET     souluongton +=
    FROM  stock st
    JOIN   (SELECT ordered, SUM(sl) AS sl
            FROM deleted
           GROUP BY ordered) AS d ON d.orderd =
    0 comments No comments