0

我正在尝试运行插入后触发器,但它不起作用,有没有办法查看它的日志?

这是我的代码

ALTER TRIGGER [dbo].[SUBSID_INSERT] on [dbo].[STUDENT_MASTER] AFTER INSERT AS
BEGIN 
SET NOCOUNT ON
DECLARE @numrows int, @hostname char(30), @sysuser char(30);

SELECT @numrows = @@rowcount;
IF @numrows = 0 RETURN;

SELECT @hostname = substring(hostname, 1, 30)
FROM master.dbo.sysprocesses
WHERE spid = @@spid;

SELECT @sysuser = substring(system_user, 1, 30);

INSERT INTO insert statement,  


FROM STUDENT_MASTER JOIN INSERTED I ON STUDENT_MASTER.ID_NUM = I.ID_NUM
JOIN NAME_MASTER ON NAME_MASTER.ID_NUM = STUDENT_MASTER.ID_NUM


WHERE 
STUDENT_MASTER.id_num not in ( select DISTINCT id_num from subsid_master where subsid_cde LIKE '0%')

END

GO
4

1 回答 1

4

@@ROWCOUNT在声明变量后进行检查。这将始终显示最后一条语句的结果(在这种情况下0),所以停止这样做。相反,只需使用:

SELECT @numrows = COUNT(*) FROM inserted;

我看到了许多其他潜在的改进,但这正是它目前似乎“不起作用”的原因。

于 2013-10-15T21:36:32.473 回答