SQL Integrity Constraints
SQL Integrity Constraints
Integrity Constraints are used to apply business rules for the database tables. The constraints available in SQL are Foreign Key, Not Null,Unique, Check. Constraints can be defined in two ways 1) The constraints can be specified immediately after the column definition. This is called column-level definition. 2) The constraints can be specified after all the columns are defined. This is called table-level definition.
This constraint defines a column or combination of columns which uniquely identifies each row in the table. Syntax to define a Primary key at column level:
column_name1, column_name2 are the names of the columns which define the primary Key. The syntax within the bracket i.e. [CONSTRAINT constraint_name] is optional. For Example: To create an employee table with Primary Key constraint, the query would be like. Primary Key at column level:
TABLE
CREATE ( name dept age salary location ALTER ); TABLE employee ADD id
CONSTRAINT
PK_EMPLOYEE_ID
PRIMARY
KEY
(id)