The topic describes the DF039 T-SQL code analysis rule.
EXECUTION RULES
The SET statement for QUOTED_IDENTIFIERS or ANSI_NULLS inside the stored procedure, trigger, or function body is used.
It is not recommended to set the QUOTED_IDENTIFIERS or ANSI_NULLS options inside a stored procedure, trigger, or function as this will have no effect.
The settings of QUOTED_IDENTIFIERS and ANSI_NULLS apply to the entire session. Setting them within a stored procedure, trigger, or function would affect only that specific object’s execution context but not the entire session. This could lead to unexpected behavior and potential conflicts with other parts of the code executing in the same session.
CREATE PROCEDURE dbo.DemoProc
AS
BEGIN
SET NOCOUNT ON;
SET QUOTED_IDENTIFIER ON;
SET ANSI_NULLS OFF;
SELECT
CityId
,CityName
FROM dbo.City;
END;
GO
SET QUOTED_IDENTIFIER ON;
SET ANSI_NULLS OFF;
GO
CREATE PROCEDURE dbo.DemoProc
AS
BEGIN
SET NOCOUNT ON;
SELECT
CityId
,CityName
FROM dbo.City;
END;
GO