By 25/02/2016 5 Comments

What Are Constraints In SQL?

  • SQL constraints are different types of rules and restrictions which are applied in data in a database table.
  • If any violation action will be taken against the data, the constraints will prevent that action.
  • The SQL constraints can be specified at table creation time with CREATE TABLE statement or after table creation by using ALTER TABLE statement.

Syntax:

CREATE TABLE table_name
(
column_name1 data_type(size) constraint_name,
column_name2 data_type(size) constraint_name,
column_name3 data_type(size) constraint_name
);

Following are SQL constraints:

Constraint Description
NOT NULL Indicates that a column cannot store NULL value. It must contains values.
UNIQUE Each row for a column must have a unique value. It has not duplicate values.
PRIMARY KEY It is used for uniquely identification for each record/row in a database table. It must be UNIQUE and NOT NULL.
FOREIGN KEY It is used for build a logically relationship between two tables. It enforces that the particular rows of both tables must be matched.
DEFAULT Set a default value for a column in database table. If you do not insert values in a table column the DEFAULT constraint sets default value for that column.
CHECK Ensures that the value in a column meets a specific condition.






Posted in: Sql

Leave your valuable Comment

Have a natural attraction for women cosmetics and replica watches uk clothes, no
more than two for men the most attractive one, is to make their own driving experience, happy and can serve as the facade of the car, another is to highlight the taste edify sentiment rolex replica watch. The replica rolex is undoubtedly the most fashionable accessories, wear a suit to attend the activities, but also get a decent match on the replica watches .