Tenho a consulta abaixo, que atualiza o carimbo de data/hora para 10 registros.
UPDATE [dbo].[file] SET timestamp = GETDATE() WHERE id <= 10
Criei um gatilho nessa tabela Inserir/Atualizar.
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER TRIGGER [dbo].[trg_file]
ON [dbo].[file]
AFTER UPDATE
AS
BEGIN
SET NOCOUNT ON;
DECLARE @ID BIGINT;
DECLARE @RES VARCHAR(100);
SET @ID = (select id from INSERTED);
SET @RES = (select timestamp from INSERTED);
IF @RES IS NOT NULL
DELETE FROM [dbo].[file] WHERE id IN (@ID)
END
Dá erro
Msg 512, Level 16, State 1, Procedure trg_file
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression.
The statement has been terminated.
Parece que o problema está aqui, pois está recebendo vários registros ao mesmo tempo.
SET @ID = (select id from INSERTED);
Como resolver isso? Via Cursor vi um pouco do post.
Quero aplicar meu gatilho na atualização de vários valores.
Qual é a melhor solução para isso?