在创建存储过程之前发布的最佳 SET 选项是什么?
例如
SET QUOTED_IDENTIFIER OFF
SET ANSI_NULLS ON
CREATE PROCEDURE HelloWorld
AS
--also, should any be issued within the procedure body?
PRINT 'hello world!'
RETURN 0
GO
我所说的最佳是指最喜欢的设置。
最佳答案
具体来说,对于存储过程创建,解析时只有两个重要
SET ANSI_NULLS
SET QUOTED_IDENTIFIER
而且它们应该ON才能使用更新的 SQL Server 功能,这些功能只能在这些 ON 状态下运行
Stored procedures execute with the SET settings specified at execute time except for SET ANSI_NULLS and SET QUOTED_IDENTIFIER. Stored procedures specifying SET ANSI_NULLS or SET QUOTED_IDENTIFIER use the setting specified at stored procedure creation time. If used inside a stored procedure, any SET setting is ignored.
引用:http://msdn.microsoft.com/en-us/library/ms190356.aspx
要同时设置和其他设置,请使用
SET ANSI_DEFAULTS ON
启用 (ON) 时,此选项会启用以下 ISO 设置:
SET ANSI_NULLS
SET CURSOR_CLOSE_ON_COMMIT
SET ANSI_NULL_DFLT_ON
SET IMPLICIT_TRANSACTIONS
SET ANSI_PADDING
SET QUOTED_IDENTIFIER
SET ANSI_WARNINGS
为了完整起见,在连接级别设置其他三个,这允许像索引 View 这样的东西正常工作
SET ARITHABORT ON
SET CONCAT_NULL_YIELDS_NULL ON
SET NUMERIC_ROUNDABORT OFF
关于sql-server - SQL Server 存储过程设置选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5278199/