0
About the following Rigger:
CREATE TRIGGER [dbo].[TG_TESTE]
ON [MINHABASE].[dbo].[TB_DOCUMENTOS]
AFTER UPDATE
AS
DECLARE @ID INT
DECLARE @DOC INT
DECLARE @QTD FLOAT
SELECT TOP 1 @ID = ID, @DOC = DOCUMENTO, @QTD = QUANTIDADE
FROM dbo.TB_DOCUMENTOS
WHERE OPERACAO = 177
AND STATUS = 1
ORDER BY ID DESC
-- CONDICAO
BEGIN
SET NOCOUNT ON;
UPDATE dbo.TB_DOCUMENTOS
SET PESO = 1000
WHERE ID = @ID
END
In the query, I filter and define the variables @ID, @DOC, @QTD
.
When that query DOES NOT RETURN a record, Trigger will run the update
within the BEGIN
, even if I don’t have a condition above ?
He will try to update anything then !? Better I put the conditions of WHERE in Trigger’s IF then !?
– rbz
select will be done anyway, even more streamlined with Where. the update Where is needed.
– Michel Simões
select yes. Ok. The
update
will be executed if it brings no record of theselect
(as you said in the reply), so he tries to apply aupdate
in no record ? It will not affect anything, but it will run !?– rbz