Constraints provide a powerful yet easy way to enforce the data integrity in your database. Data integrity comes in three forms:

  • Entity integrity. Ensures that a table has a primary key. In SQL Server 2005, you can guarantee entity integrity by defining PRIMARY KEY or UNIQUE constraints or by building unique indexes. Alternatively, you can write a trigger to enforce entity integrity, but this is usually far less efficient.

  • Domain integrity. Ensures that data values meet certain criteria. In SQL Server 2005, domain integrity can be guaranteed in several ways. Choosing appropriate data types can ensure that a data value meets certain conditions–for example, that the data represents a valid date. Other approaches include defining CHECK ...

Get Inside Microsoft® SQL Server™ 2005, Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.