The Wrecking Bawl

Destructuring query language, one keyword at a time.


News


It's amazing that to this day I still forget sometimes that any comparison with NULL is "unknown."  Case in point, I have 105 tables in my database, but when I run the query below I only get 84 rows (assume for now that I only have one key per table), which briefly baffled me.  The reason for this is that t2.table_name is NULL in 21 cases, and when SQL Server attempts to compare 'dtproperties' to NULL, it doesn't get TRUE or FALSE, it gets UNKNOWN.  Thanks to Michael Coles for reminding me of this, and for elaborating.

SELECT *
FROM INFORMATION_SCHEMA.TABLES t1
FULL OUTER JOIN INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE t2
ON t1.table_name = t2.table_name
WHERE t2.table_name != 'dtproperties'
  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

Comments

No comments posted yet.
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: