Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
236 views
in Technique[技术] by (71.8m points)

Why does SQL Server require ansi_nulls to be on to create an index?

Some actions in SQL Server will throw an error if executed after SET ANSI_NULLS OFF. The remedy is simple, I just have to SET ANSI_NULLS ON (and make sure my queries aren't adversely affected by the different way it compares nulls).

This is known behaviour. The official documentation says this:

ANSI_NULLS is one of seven SET options that must be set to required values when dealing with indexes on computed columns or indexed views.

But why is it so? Is there a technical reason why this variable must be set to ON?

question from:https://stackoverflow.com/questions/65713809/why-does-sql-server-require-ansi-nulls-to-be-on-to-create-an-index

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It has a base in being deterministic.

A calculated column or an indexed view for example must always return the same data no matter what the session settings are, and therefore they are forced to behave in a consistent manner by the engine.

The example here in the indexed view page shows one example of where different options can change the behaviour. Because a calculation could in some cases use an equality comparison between columns, consistent behaviour is needed here too


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...