I have a trigger that updates one of the inserted fields (RootId) with the value of the identity primary key (MessageId) of the same inserted record. The update should only happen when the RootId field of the inserted record is 0. The trigger looks like this:
ALTER TRIGGER [dbo].[Trigger_RootIdUpdate]
ON [dbo].[Messages]
AFTER INSERT
AS BEGIN
SET NOCOUNT ON;
DECLARE @MessageId Int
SELECT @MessageId = I.MessageId
FROM INSERTED I
UPDATE Messages
SET RootId = @MessageId
WHERE MessageId = @MessageId AND MessageId = 0
END
I use it in Azure and when I insert a row, it gives me the following error:
The target table 'dbo.Messagess' of the DML statement cannot have any enabled triggers if the statement contains an OUTPUT clause without INTO clause.
The same trigger works on my real MS SQL 2012. I assume there is a difference in the settings but I do not get what it tries to tell me.
Am I overcomplicating something? Thanks!