CONSTRAINTS on SQL
These are the objects used to validate the data entry in tables columns.
-TYPES OF CONSTRAINTS:---
-1)Primary key:-Checks for duplicate and null values.
-Primary key can be defined for single or composite columns.
One Primary key per table.
2)Unique key:-checks for duplicate values. One null value is allowed.
3)Check:-The data must obey the rules of comparison operators(=, < ,> ,<=,>=, in
between, like).
4)Rules:-They are like the check constraints but have certain differences.
-Check constraints are applied with the column definitions.
Rules are created separately and then can be attached with different columns of
different tables.
Check constraints check for existing data, rules do not check for the existing
data.
5)Not Null:-we have to enter the values on the columns where not null constraint
is defined.
6)Foreign key:--Used for Referential integrity:-
-If we insert a particular data in a table column, then matching data should be
inserted in the column where the foreign key is defined. The Foreign key will
check for data by referencing the column where data is inserted.
The referenced column must have primary key or unique key associated with it.
Constraints can be created using the Create Table or alter table clause.
-Candidate keys:--
--These are a set of columns used to uniquely identify
the rows.The first will be a primary key.
other keys are known as alternate keys
-eno , ename, hiredate, salary
-(eno,ename):primary key(composite)
CONSTRAINTS on SQL
Reviewed by Rupesh
on
12:52
Rating:
No comments: