Wednesday, January 18, 2012

Data Integrity

Data Integrity means data validation or data checking process or type checking process. Before storing user supplied information into the table server performs data integrity process in order verify whether user supplying valid information or not.
If user supplies valid information then only it will get stored into the table otherwise server raises an error message.
We can achieve this data integrity in three ways:
1.       Data Types
2.       Constraints
3.       Triggers
Constraints: Constraint is nothing but condition on column. If we perform any operation against to constraint server raises an error message.
Type of Constraints:
NOT NULL:  When we place a NOT NULL constraint on any column, it will not allow duplicate values. Entering value for that column is mandatory.
UNIQUE: When we place UNIQUE constraint on any column, it will not allow duplicate values but it allows single null value.
CHECK: It is used for evaluating range condition on numeric columns. It is used for evaluating character comparison conditions on character columns.
PRIMARY KEY: It is a combination of UNIQUE + NOT NULL + CLUSTERED INDEX.
It means when we place PRIMARY KEY constraint on any column then it will not allow any duplicate values and it does not accept any null values mean time the data in that column will be arranged in ascending order due to CLUSTERED INDEX.
FOREIGN KEY: FOREIGN KEY must be PRIMARY KEY.
FOREIGN KEY can accept duplicate values and NULL values.
FOREIGN KEY can accept duplicate values and NULL values.
FOREIGN KEY has to take the values from its corresponding PRIMARY KEY.

1 comment:

  1. Hey Nagarjun, can you pls tell what is the difference between data integrity and data consistency?

    ReplyDelete