2 ms·
SQL Server has a setting ANSI_NULLS, which defaults to on. In this state, the behavior is exactly as you expect. It takes explicit action to change it from the
by CWuestefeld 15y ago
SQL Server has a setting ANSI_NULLS, which defaults to on. In this state, the behavior is exactly as you expect. It takes explicit action to change it from the standard.
That said, the SQL standard is already inconsistent in this respect, which annoys me. You are allowed to use equality in setting a value:
update mytable set mycol=NULL where mykey=2
If I'm allowed to assign a value of null, why can't I compare it? If NULL is so special that its value cannot be compared, then what does it mean when I assign that "value"? The assignment operation makes a copy of the specified value into the target column; how can I make that copy of the specified value if it's impossible to say that two NULLs are the same?