简体   繁体   English

创建/修改具有不同 QUOTED_IDENTIFIER 值的多个对象(在存储过程中)

[英]Create/Amend multiple objects (within a sproc) with different QUOTED_IDENTIFIER values

As a development aid, I am writing a stored procedure which creates/amends database objects from one database into another one.作为开发辅助,我正在编写一个存储过程,该过程将数据库对象从一个数据库创建/修改到另一个数据库。 (The sproc takes a CSV string of object names, which it splits into individual values using XML, and therefore the QUOTED_IDENTIFIER needs to be turned on for the sproc to run.) (存储过程采用 CSV 字符串 object 名称,它使用 XML 将其拆分为单独的值,因此需要为运行过程打开QUOTED_IDENTIFIER 。)

However, the objects being created/amended include stored procedures where QUOTED_IDENTIFIER could be turned either on or off.但是,正在创建/修改的对象包括可以打开或关闭QUOTED_IDENTIFIER的存储过程。

According to the answer to this very similar question (which talks specifically about creating a single stored procedure) if you create/amend a stored procedure within another stored procedure, it will always use the QUOTED_IDENTIFIER values set in the "parent" sproc.根据这个非常相似的问题的答案(专门讨论创建单个存储过程),如果您在另一个存储过程中创建/修改存储过程,它将始终使用“父”存储过程中设置的QUOTED_IDENTIFIER值。

Does anybody know of a way to be able to set different QUOTED_IDENTIFIER flag values when creating/amending multiple stored procedures?有人知道在创建/修改多个存储过程时能够设置不同的QUOTED_IDENTIFIER标志值的方法吗?

I've tried very simple code within the loop (such as the following) but as the above answer suggests, this has no effect on the result and the created/amended sproc always has QUOTED_IDENTIFIER set to ON ...我在循环中尝试了非常简单的代码(如下所示),但正如上面的答案所暗示的,这对结果没有影响,并且创建/修改的 sproc 总是将QUOTED_IDENTIFIER设置为ON ...

IF @QUOTED = 1 -- from sys.sql_modules.uses_quoted_identifier
  SET QUOTED_IDENTIFIER ON
ELSE
  SET QUOTED_IDENTIFIER OFF

EXEC sp_executesql @DEFINITION -- from sys.sql_modules.definition

With many thanks to @Jeroen who sent me down the path to the solution, which is to create another development-aid stored procedure with QUOTED_IDENTIFIER set to OFF .非常感谢@Jeroen ,他让我找到了解决方案,即创建另一个开发辅助存储过程,并将QUOTED_IDENTIFIER设置为OFF

Within the main loop of the primary development-aid sproc it executes the definition through itself (if ON is required) or through the secondary sproc (if OFF is required).在主要开发辅助存储区的主循环中,它通过自身(如果需要ON )或通过辅助存储区(如果需要OFF )执行定义。

This is a very simplified pseudo version of what I now have working...这是我现在工作的一个非常简化的伪版本......

SET QUOTED_IDENTIFIER OFF
GO
CREATE PROCEDURE DEV_AID_SUB
  @DEFINITION NVARCHAR(MAX)
AS
  EXEC sp_executesql @DEFINITION

---

SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE DEV_AID
AS
BEGIN
  WHILE @LOOP = 1
    IF @QUOTED = 1
      EXEC sp_executesql @DEFINITION
    ELSE
      EXEC DEV_AID_SUB @DEFINITION
  END
END

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ANSI_NULLS和QUOTED_IDENTIFIER行为 - ANSI_NULLS and QUOTED_IDENTIFIER Behavior 存储过程中的 SET QUOTED_IDENTIFIER - SET QUOTED_IDENTIFIER in stored procedure 在现有约束/规则/程序上更改 Quoted_Identifier - Changing Quoted_Identifier on existing Constraints / Rules / Procedures 使用QUOTED_IDENTIFIER克服'ALTER INDEX failed'错误 - Use of QUOTED_IDENTIFIER to overcome 'ALTER INDEX failed' error 如果您有索引视图,为什么整个数据库都必须启用QUOTED_IDENTIFIER? - Why must QUOTED_IDENTIFIER be on for the whole db if you have an indexed view? 修改查询以根据特定列检查组内的多个值 - Amend Query To Check For Multiple Values Within A Group Based On Specific Column 由于使用了XML / ANSI_NULLS,QUOTED_IDENTIFIER选项,SQL Server存储过程失败 - SQL Server Stored Procedure Fails due to use of XML/ ANSI_NULLS, QUOTED_IDENTIFIER options SQL Server代理发出的第一条语句将quoted_identifier设置为off - First statement issued by SQL Server Agent sets quoted_identifier off 删除所有表时出错“DELETE 失败,因为以下 SET 选项的设置不正确:'QUOTED_IDENTIFIER'” - Error deleting all tables "DELETE failed because the following SET options have incorrect settings: 'QUOTED_IDENTIFIER'" 用于多个数据库的DBCC SHRINKFILE 1 sproc - DBCC SHRINKFILE 1 sproc for multiple databases
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM