我在我的表中更新了列(延迟)之后写了触发器来执行查询,但是有时会有很多行更新如何解决?
CREATE OR ALTER TRIGGER notifRetard
ON Taches
AFTER UPDATE
AS
BEGIN
SET NOCOUNT ON;
DECLARE @value INT
IF UPDATE(retard)
-- How to make this for every row updated???
SELECT
@value = inserted.retard
FROM
inserted;
IF @value = 1
-- run SQL query
END
如果其他人需要它的解决方案是使用CURSOR。
CREATE or alter TRIGGER notifRetard
ON Taches
AFTER UPDATE
AS
BEGIN
SET NOCOUNT ON;
IF UPDATE(retard)
begin
DECLARE @RefTache varchar(50),@RefPhase numeric(4,0),@IDprojet varchar(50),@IDressource varchar(50) @retard bit;
DECLARE TrigTempUpdate_Cursor CURSOR FOR
SELECt RefTache,RefPhase,IDprojet,IDressource,retard
FROM
inserted;
begin
OPEN TrigTempUpdate_Cursor;
FETCH NEXT FROM TrigTempUpdate_Cursor INTO @RefTache, @RefPhase,@IDprojet,@IDressource,@retard
WHILE @@FETCH_STATUS = 0
BEGIN
if @retard=1
--DO QUERY HERE
FETCH NEXT FROM TrigTempUpdate_Cursor INTO @RefTache, @RefPhase,@IDprojet,@IDressource,@retard
END;
end;
CLOSE TrigTempUpdate_Cursor;
DEALLOCATE TrigTempUpdate_Cursor;
end;
end;