Different constraints in SQL
Constraints
in SQL:
Constraints
are the rules enforced on data columns on table.
These are used to limit the type of data that can go into a table and It ensures the accuracy and reliability of the data in the database.
Constraints
are of two types:
Column
level: These are applied only to one column
Table
level: These are applied to the whole table
Below
are the commonly used constraints in SQL.
UNIQUE:
Ensures that all values in a column are different and we can have one
NULL value in this type of column.
PRIMARY:
Uniquely identified each rows/records in a database table and we
cannot have NULL value in this type of column.
Constraints
can be specified when we are creating the table or we can add
constraints to the table even after the table is created.
Dropping Constraints:
Any
constraint that you have defined can be dropped using the ALTER TABLE
command with the DROP CONSTRAINT option.
For
example, to drop the primary key constraint on the EMPLOYEE table,
you can use the following command:
ALTER
TABLE
Employee
DROP
CONSTRAINT
Employee_PK
Integrity Constraints:
Integrity
constraints are used to ensure accuracy and consistency of data in a
relational database.
Data
integrity is handled in a relational database through the concept of
referential integrity.
There
are many types of integrity constraints that play a role in
referential integrity (RI). These constraints include Primary Key,
Foreign Key, Unique Constraints and other constraints mentioned
above.
Labels: CHECK, Constraints in SQL, deafault constraint, Foreign Key, integrity constraints, PRIMARY Key, SQL Basics, SQL Learning
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home