When you create a CHECK
constraint in SQL Server, you might not even think about whether it’s a table-level constraint or a column-level constraint.
A table-level CHECK
constraint applies to the table, whereas a column-level constraint applies to a specific column. With a table-level CHECK
constraint, it’s the row that is checked when it checks the data. With a column-level CHECK
constraint, it’s the specific column that is checked.
Generally you’ll know whether or not the constraint you’re creating is a table-level or column-level constraint by the definition you give it. If only one column is being checked in the expression, it will be a column-level constraint. Otherwise it will be a table-level constraint.
But how do you know if your existing constraints are column-level or table-level?
You can run any of the code examples below to determine whether your existing constraints are column-level or table-level. These retrieve all CHECK
constraints for the current database, but you can always use a WHERE
clause to narrow it down to a specific constraint.