对于存储过程,SQL Server 使用最初创建存储过程时的 SET ANSI_NULLS 设置值。无论随后何时执行存储过程,SET ANSI_NULLS 的设置都还原为其最初使用的值并生效。当在存储过程内唤醒调用 SET ANSI_NULLS 时,其设置不更改。
--try create table T(col1 int, col2 int) insert T select 1, 1 insert T select 2, null insert T select 3, 3set ansi_nulls off go create proc pc as select * from T where col2 = null goset ansi_nulls on goexec pc go
create table T(col1 int, col2 int)
insert T select 1, 1
insert T select 2, null
insert T select 3, 3set ansi_nulls off
go
create proc pc
as
select * from T where col2 = null
goset ansi_nulls on
goexec pc
go
-----------------------------------------------------
set ansi_nulls off 是默认设置