NULLs and Other SQL Gotchas Wendy Pastrick
About DBA since 2000 Salesforce Performance DBA Data Platform MVP since 2013 PASS Board of Directors – Virtual Chapters
Data Data Data Null ANSI settings Unknown NULL = NULL Validation ISNULL = NULL
No Data? Empty vs Null Datatype matters! Integer – converts to 0 String – Empty (‘’) Date -- 1900-01-01 00:00:00.000
Fallout Your SQL code that would otherwise expect to work like the IS NULL or IS NOT NULL checks won’t work anymore In case you were doing this for a number column, the aggregate functions like AVG() which otherwise would be ignoring the Null value will now count the record https://decipherinfosys.wordpress.com/2009/03/27/null-vs-empty-zero-length-string/
Fallout…more The SQL code which uses functions like ISNULL(), COALESCE() etc. will not function as expected since these fields will not have a Null value. The sorts won’t work as expected since Null and the empty string (and the subsequent default value that actually gets inserted) are not the same thing.
….and even More If you have this column as part of the foreign key, you will get an error at the time of the insert itself since instead of a Null value, the code will try to insert another default value in and it will violate the FK constraint. Any concatenation operations or MAX(), MIN() functions can lead to un-desired results.
Scalar Functions Performance killer RBAR Only returns a single value per input Table Valued Functions preferable, but still not awesome.
Thank You! Wendy.Pastrick@gmail.com Resources https://sqlstudies.com/2014/07/14/what-does-it-mean-that-a-value-is-null/ http://www.sqlservercentral.com/blogs/sqlstudies/2014/07/28/what-is-ansi_nulls-and- why-will-i-be-glad-when-it-finally-goes-away/ http://thomaslarock.com/2009/03/sql-server-and-null-values/ https://decipherinfosys.wordpress.com/2007/07/18/empty-string-and-integer-data- type/ https://decipherinfosys.wordpress.com/2009/03/27/null-vs-empty-zero-length-string/ http://sqlblog.com/blogs/aaron_bertrand/archive/2009/10/12/bad-habits-to-kick- using-the-wrong-data-type.aspx