0
我試圖通過使用遊標來實現行級刪除觸發器,但是當試圖從表中刪除任何行時,它花了很長時間。SQL Server行級觸發器
我無法理解它究竟卡在哪裏。
/****** Object: Trigger [delStudent] Script Date: 06/24/2010 12:33:33 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TRIGGER [delStudent]
ON [dbo].[Student]
FOR DELETE
AS
DECLARE @Roll as varChar(50);
DECLARE @Name as varChar(50);
DECLARE @Age as int;
DECLARE @UserName as varChar(50);
SELECT @UserName=SYSTEM_USER;
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;
BEGIN TRANSACTION;
declare CurD cursor for select roll, Sname, age from deleted
open CurD
WHILE @@FETCH_STATUS = 0
BEGIN
INSERT INTO [dbo].[Audit]
(roll,sname,age,userId)
VALUES
(@Roll,@Name,@Age,@UserName)
END
COMMIT TRANSACTION;
Close CurD
DEALLOCATE CurD
你的數據庫的大小和「學生」表中有多少行? – Samiksha 2010-06-24 07:15:41
這裏沒有理由使用光標。你爲什麼使用一個? – codingbadger 2010-06-24 07:23:58
我懷疑你的參數是否包含任何值。他們從未被分配。 – user3208055 2014-01-17 19:40:24