The first example declares a limit on a string , the second does not. Only simple keys (including one attribute) can be declared in a row, composite keys (involving multiple columns) cannot. But both table level restrictions!
There are four logical levels of restriction:
1) Column level:
CHECK ( ProductID > 0 )
2) Line Level:
CHECK ( Product_start_date < Product_end_date )
3) Table level (the following example is not yet supported in SQL Server):
CHECK ( NOT EXISTS ( SELECT * FROM ( SELECT ROW_NUMBER() OVER ( PARTITION BY ProductID ) AS Tally FROM Products AS P ) AS DT1 WHERE Tally > 1 ) )
4) Database level (not yet supported in SQL Server):
CREATE ASSERTION EnterpriseUniqueIds CHECK ( NOT EXISTS ( SELECT * FROM ProductID AS P JOIN Components AS C ON C.ComponentID = P.ProductID ) );
A key limitation involves comparing different rows in the same table, so this is a table-level limitation.
onedaywhen
source share