Integrity Constraint in SQL

In this blog, we’ll discuss about Integrity constraint in SQL Server.

Integrity constraint are rules implemented in the tables to guarantee the accuracy, completeness, or consistency of data in tables and keep safe the business logic of the schema design.Constraints are part of a database schema definition

In SQL, all the constraints are mainly grouped together in 4 major types, they are:

  1. Primary integrity : which can be done by using
    1. PRIMARY KEY
    2. UNIQUE KEY
  2. Referential integrity : which can be done by using
    1. FOREIGN KEY
  3. Domain integrity : which can be done by using
    1. DEFAULT
    2. NOT NULL
    3. CHECK
  4. User Defined integrity : which can be done be using
    1. RULE

Please click on each constraints for detail explanation.

To get the details (like Constraint_Type,Constraint_Name,Constraint_Keys, enable / disable etc. ) of all the constraint define in a table execute the system procedure with table name.

EXEC sp_helpconstraint ‘dbo.Employee1’

Few examples might not work properly in MS SQL version less than 2008 R2. Please share your valuable comments.

Advertisements

One thought on “Integrity Constraint in SQL

  1. Pingback: Learn Microsoft SQL | Lessons I Learned from sql

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s