Zawsze zastanawiam się nad jakimś tajemniczym zachowaniem t-sql, jak poniżej
-- Create table t and insert values.
use tempdb
CREATE TABLE dbo.t (a INT NULL);
-- insert 3 values
INSERT INTO dbo.t values (NULL),(0),(1);
GO
set ansi_nulls off -- purposely turn off, so we can allow NULL comparison, such as null = null
go
-- expect 3 rows returned but only 2 returned (without null value row)
select * from dbo.t where a = a
Nie chodzi tu o to, jak pobrać wszystkie wiersze w tabeli, a także o unikanie użycia ANSI_NULLS.
Chcę tylko uzyskać pewne spostrzeżenia, dlaczego t-sql zachowuje się w ten sposób.