Constraints
Constraints
Foreign key
CHECK
Whenever a check constraint is
applied to the table's column,
and the user wants to insert the
value in it, then the value will
first be checked for certain
conditions before inserting the
value into that column.
CHECK(Contd…)
CREATE TABLE student(StudentID
INT, Student_Name VARCHAR(20),
Age INT CHECK( Age <= 15));
If CHECK constraint is not given at
the time of creation we can add
using
ALTER TABLE student ADD CHEC
K ( Age <=15 );
DEFAULT
Whenever a default constraint is
applied to the table's column,
and the user has not specified
the value to be inserted in it,
then the default value which was
specified while applying the
default constraint will be inserted
into that particular column.
DEFAULT(Contd…)
CREATE TABLE student(StudentID
INT, Student_Name VARCHAR(20
), Student_Email_ID VARCHAR(40)
DEFAULT “[email protected]");
Domain Constraints
Domain constraints are user defined data type and we can define
them like this:
Domain Constraint = data type + Constraints (NOT NULL / UNIQUE /
PRIMARY KEY / FOREIGN KEY / CHECK / DEFAULT)