EXEC and Set Quoted_Identifier

后端 未结 1 1692
暗喜
暗喜 2021-01-23 06:08

I\'ve got a Stored proc [A] that creates another stored proc [B]

[A] Will never be run by end users and has no parameters or other untrusted data. Instead it is used by

1条回答
  •  悲&欢浪女
    2021-01-23 07:01

    You need QUOTED_IDENTIFIER to be ON where stored procedure A is created. Note:

    When a stored procedure is created, the SET QUOTED_IDENTIFIER and SET ANSI_NULLS settings are captured and used for subsequent invocations of that stored procedure.

    Which, by implication, means that any stored procedure that creates stored procedures will pass on the settings that were in force during its own creation. E.g.:

    set quoted_identifier on
    go
    create procedure ABC
    as
        exec('create procedure DEF as')
    go
    set quoted_identifier off
    go
    exec ABC
    go
    select definition,uses_quoted_identifier from sys.sql_modules
    where object_id=OBJECT_ID('DEF')
    

    produces:

    definition                             uses_quoted_identifier
    -------------------------------------- ----------------------
    create procedure DEF as                1
    

    0 讨论(0)
提交回复
热议问题