i have a trigger running against a table that does not return a results set:
ALTER TRIGGER [dbo].[LogDelete_Nodes] ON [dbo].[Nodes]
FOR DELETE
AS
BEGIN
SET NOCOUNT ON;
/* Load the saved context info UserGUID */
DECLARE @SavedUserGUID uniqueidentifier
SET @SavedUserGUID = (SELECT CAST(context_info as uniqueidentifier)
FROM master.dbo.sysprocesses
WHERE spid = @@SPID)
--remaining trigger contents deleted to provide simple example
END;
Deleting rows from the Nodes table will cause the error:
Msg 524, Level 16, State 1, Procedure LogDelete_Nodes, Line 10
A trigger returned a resultset and the server option ‘disallow results from triggers’ is true.
How do i make a trigger that does not return a resultset not return a resultset?
Note: The trigger was originally defined to use the non-deprecated syntax for setting a variable:
SELECT @SavedUserGUID = CAST(context_info as uniqueidentifier)
FROM master.dbo.sysprocesses
WHERE spid = @@SPID
and it still gives the same error.
SELECT @@version
Microsoft SQL Server 2005 - 9.00.4035.00 (Intel X86) Nov 24 2008 13:01:59
Copyright (C) 1988-2005 Microsoft Corporation
Enterprise Edition on Windows NT 5.2 (Build 3790: Service Pack 2)
Answer to follow
We figured out the problem while i was composing this question. i’m still going to ask the question, since the answer can prove to be very helpful to anyone else having this mysterious problem.
The solution to the problem turned out to be because the SSMS option Include Actual Execution Plan was enabled.
SQL Server is (mistakenly) counting the “secret” resultset containing execution plan information as being returned by the trigger.
Turn off the option to see the execution plan, and it works. This makes tracing execution plans difficult, since you’re not allowed to see execution plans.
This is most likely a bug in SQL Server 2005.