Hãy nói rằng tôi đã có một kích hoạt như thế này:T-SQL: Một cách thích hợp để CLOSE/deallocate con trỏ trong bản cập nhật cò
CREATE TRIGGER trigger1
ON [dbo].[table1]
AFTER UPDATE
AS
BEGIN
--declare some vars
DECLARE @Col1 SMALLINT
DECLARE @Col1 TINYINT
--declare cursor
DECLARE Cursor1 CURSOR FOR
SELECT Col1, Col2 FROM INSERTED
--do the job
OPEN Cursor1
FETCH NEXT FROM Cursor1 INTO @Col1, @Col2
WHILE @@FETCH_STATUS = 0
BEGIN
IF ...something...
BEGIN
EXEC myProc1 @param1 = @Col1, @Param2 = @Col2
END
ELSE
IF ...something else...
BEGIN
EXEC myProc2 @param1 = @Col1, @Param2 = @Col2
END
FETCH NEXT FROM Cursor1 INTO @Col1, @Col2
END
--clean it up
CLOSE Cursor1
DEALLOCATE Cursor1
END
Tôi muốn chắc chắn rằng Cursor1 luôn đóng cửa và deallocated. Ngay cả myProc1 hoặc myProc2 đều thất bại.
Tôi có nên sử dụng khối try/catch không?
[đọc bắt buộc] (http://www.sommarskog.se/error-handling-I.html). –