Creating Constraints

You can define constraints on a single column or on multiple columns. Single-column constraints are referred to as column-level constraints. You can define this type of constraint when you create the column on the table. Constraints that reference multiple columns must be defined on the table and are considered table-level constraints. Table-level constraints must be defined after all the referenced columns in the table are created.

Using T-SQL to Create Constraints

You can create constraints with T-SQL by using the CREATE TABLE or ALTER TABLE statement. When you create a column-level constraint by using the CREATE TABLE statement, the CONSTRAINT keyword and constraint definition are included immediately after the column ...

Get Microsoft® SQL Server 2008 R2 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.