Constraints in SQL Server are used to ensure the integrity of the system. General constraints can be divided into:
PRIMARY KEY constraint
FOREIGN KEY constraints
CHECK constraints
Default Constraints
Unique constraint
Non-null constraint
But in general we need to pay special attention to the first three constraints:
A PRIMARY key constraint, which is a significant relationship to the entity of your system, is used to ensure the integrity of the entity. Requires a table to have only one entity, and in experience it is not possible to have tables in a table. Is it similar to the concept of the first paradigm? Similar to the right, generally do a table of one entity will satisfy the first paradigm
FOREIGN KEY constraints
A FOREIGN key constraint is to ensure the integrity of the reference. In other words, each outside of your system must correspond to an entity (the primary KEY constraint) and not be arbitrarily confused. This is mainly to meet the requirements of the second paradigm
CHECK constraints and default constraints are to ensure the integrity of the data. For example, if you have a table of age field, then be sure to check if he is greater than 0. This is the third paradigm that is mainly said.
We generally do design only need to achieve the second paradigm, blindly meet the three paradigms, in fact, the system will be very large, the maintenance of the later optimization does not have any benefits. The appropriate redundancy data is powerful for the system
The role of SQL Server constraints is to understand [go]