Predicate syntax?
I do not see where the book explains the syntax of predicates, yet they are critical for even simple databases, appearing in SELECT/DELETE/UPDATE WHERE, GROUP BY HAVING, and ADD CONSTRAINT clauses. There does not seem to be any explanation of AND, OR, NOT, IS NULL, parentheses or operators. For example, validating Day for the INT columns Day, Month, Year takes this predicate:
Day IS NULL OR Day BETWEEN 1 AND 28
OR Day BETWEEN 29 AND 31 AND Month IN(1, 3, 5, 7, 8, 10, 12)
OR Day BETWEEN 29 AND 30 AND Month IN(4, 6, 9, 11)
Day = 29 AND Month = 2 AND Year % 4 = 0 AND (Year % 100 != 0 OR Year = 2000)
Readers also ought not to be surprised when on retrieval this predicate comes back from SQL Server 2005 as:
([Day] IS NULL OR [Day]>=(1) AND [Day]<=(28) OR [Day]>=(29) AND [Day]<=(31) AND ([Month]=(12) OR [Month]=(10) OR [Month]=(8) OR [Month]=(7) OR [Month]=(5) OR [Month]=(3) OR [Month]=(1)) OR [Day]>=(29) AND [Day]<=(30) AND ([Month]=(11) OR [Month]=(9) OR [Month]=(6) OR [Month]=(4)) OR [Day]=(29) AND [Month]=(2) AND [Year]%(4)=(0) AND ([Year]%(100)<>(0) OR [Year]=(2000)))
|