What is a constraint in Sql Server and explain different types of constraints?

Constraints are allows us to enforce rules in our database. Sql Server support 6 types of constraints.

    PRIMARY KEY constraint is a unique identifier for a row within a database table. Every table should have a primary key constraint to uniquely identify each row. The primary key constraints are used to enforce entity integrity(refer RDBMS FAQ's).

    UNIQUE constraint enforces the uniqueness of the values in a set of columns, so no duplicate values are entered. The unique key constraints are used to enforce entity integrity as the primary key constraints.

    FOREIGN KEY constraints are fields in a relational database table that match the primary key column of another table. Foreign keys can be used to cross-reference tables.

    CHECK constraint is used to limit the values that can be placed in a column. The check constraints are used to enforce domain integrity.

    NOT NULL constraint enforces that the column will not accept null values. The not null constraints are used to enforce domain integrity, as the check constraints.

    DEFAULT constraints allow you to specify a value that the database will use to populate fields that are left blank in the input source.


No comments:

Post a Comment