sql server - constraints

Post on 20-Jan-2017

889 Views

Category:

Technology

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Constraints

Presentation by Aaron BumaDev Lead and DBA

Session Overview

•Constraints

•Data Integrity

•Demos

Primary Key Constraint

•Most common constraint

•Doesn’t allow NULL or duplicates

•There can only be one per table

Unique Constraint

•Can be used when a table already has a Primary Key

•Does not allow duplicates, but DOES allow a NULL

Check Constraint

•Enforces domain integrity, data must conform

•Can refer to a single or multiple columns

•Example: column value must be > 3.

Default Constraint

•Useful for inserting data into “NOT NULL” columns

•Can be dynamic, example: Using GETDATE()

•Can be overridden with actual values

Foreign Key Constraint

•A value in the FK’d table exists as a Primary Key of a table, usually a different one

•Verifies constraint on EXISTING data and NEW data– “WITH NOCHECK” only verifies NEW data

Data Integrity

•Domain Integrity (Constraint on individual value)– Check Constraints

•Entity Integrity (Looks at entire table)– Primary Keys, Unique Constraints

•Referential Integrity (must exist in other table)– Foreign Keys

DEMOS

Review

• Constraints

• Data Integrity

Presentation Recording, Slides and Scripts– Available at: http://www.AaronBuma.com

top related