Enforcing Data Integrity and Relationships between Tables

When creating tables in a database, you often need to define rules regarding the values allowed in columns (fields). As mentioned in Chapter 19, constraints allow you to enforce integrity by creating rules for a table. The five types of constraints are listed below.

Table 20-1: Table constraints

Constraint Name

Usage

PRIMARY KEY

Identifies the column or set of columns whose values uniquely identify a row in a table.

FOREIGN KEY

Defines the relationship between tables and maintains data integrity when records are being added, changed, or deleted in a table.

UNIQUE

Ensures that no duplicate values are entered in a specific column or combination of columns that is not a table's primary key.

NOT NULL

Specifies that a column cannot contain a Null value. Primary key columns are automatically defined as NOT NULL.

Note: A Null value is not the same as zero (0), blank, or a zero-length character string (" "). A Null value indicates that no entry has been made. You can determine if a field contains a Null value by using the IsNull function.

CHECK

Enforces integrity by limiting the values that can be placed in a column.

When constraints are added, all existing data is verified for constraint violations.

Part III

0 0

Post a comment