Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
http://mssqlsolutions.blogspot.com
Constraints
1.
2.
3.
4.
5.
6.
Primary Key
Foreign Key
Unique
Check
Default
Allow Nulls/Not Null
1. Not Null
2. No duplicates
Can be a single column or set of columns that uniquely
identify a row in table.
Can not have NULL value.
Only one (1) Primary Key per table.
If it is used as a Foreign key (FK) constraint in any other
table, first delete FK constraint before deleting PK.
To modify existing PK, first delete existing PK and then
re-create new one.
Implementing PK
by SSMS
Open Table in design mode, select columns favorable for PKs, right click on them and apply
Set Primary Key option.
Unique Constraint
Enforces uniqueness of the values in a set of columns
Step2 -
Implementing Foreign
Key by SSMS
Step1 - Open Table in design mode, right click on any column and choose Relationships
option.
Implementing Foreign
Key by SSMS
Step2 -
Check Constraint
Enforces domain integrity by limiting the values that can be
put in a column.
Evaluates to True/False/Unknown.
Multiple Check Constraint can be applied to a single column.
Check constraints performed only during Insert and Update
statements.
Implementing Check
Constraint by SSMS
Step1 - Open Table in design mode, right click on any column and choose Check
Constraints option.
Implementing Check
Constraint by SSMS
Step2 -
Default Constraint