简体   繁体   English

如何在ANSI_NULLS设置为OFF的情况下为过程远程更改ANSI_NULLS或迁移过程

[英]How to change ANSI_NULLS remotely for a procedure or migrate procedure with ANSI_NULLS set OFF

I know there are numerous topics regarding migrating or syncing stored procedures to another server, anyhow, I'm not able to find out some acceptable answer to following question. 我知道有很多关于将存储过程迁移或同步到另一台服务器的主题,无论如何,我无法找到以下问题的可接受答案。

I want to migrate stored procedure with ANSI_NULL value set to OFF by a script. 我想通过脚本将ANSI_NULL值设置为OFF的存储过程进行迁移。 Example of the procedure I want to migrate: 我要迁移的过程示例:

USE [myDB]
GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[p_test_ansi_nulls] AS
SELECT CASE WHEN NULL = NULL THEN 'haha' ELSE 'no-haha' END h

ANSI_NULLS value is stored in sys.sql_modules table, but not in the procedure itself. ANSI_NULLS值存储在sys.sql_modules表中,但不存储在过程本身中。 I tried to create statement with the header (with SET ANSI_NULLS OFF string included) and execute via sp_executesql, but got an error: 我试图创建带有标题的语句(包括SET ANSI_NULLS OFF字符串)并通过sp_executesql执行,但出现错误:

'CREATE/ALTER PROCEDURE' must be the first statement in a query batch. “ CREATE / ALTER PROCEDURE”必须是查询批处理中的第一条语句。

So is there any way, how to migrate procedure to another server with this option or way how to change this setting remotely? 那么,有什么方法,如何使用此选项将过程迁移到另一台服务器或如何远程更改此设置? (procedure is quite old and complex, therefore we can't change the code..) (过程非常老而且复杂,因此我们无法更改代码。)

Do it exactly the way you wrote up there. 完全按照您在此处撰写的方式进行操作。

SET ANSI_NULLS OFF
GO
CREATE PROCEDURE [dbo].[p_test_ansi_nulls] AS
SELECT CASE WHEN NULL = NULL THEN 'haha' ELSE 'no-haha' END h

This will create procedure with ANSI_NULLS off: 这将创建关闭ANSI_NULLS过程:

SQLFiddle DEMO SQLFiddle演示

Also, pease note - from msdn: http://msdn.microsoft.com/en-us/library/ms188048.aspx 另外,请注意-来自msdn: http : //msdn.microsoft.com/zh-cn/library/ms188048.aspx

In a future version of SQL Server, ANSI_NULLS will always be ON and any applications that explicitly set the option to OFF will generate an error. 在SQL Server的未来版本中,ANSI_NULLS将始终为ON,并且任何将选项显式设置为OFF的应用程序都将产生错误。 Avoid using this feature in new development work, and plan to modify applications that currently use this feature. 避免在新的开发工作中使用此功能,并计划修改当前使用此功能的应用程序。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM