Constrains
Constrains
contain a value. Or
NOT NULL constraint on a column is used to tell the
SELECT *
FROM EmployeeDetails
GO
Types of Keys
CHECK Constraint:
A check constraint implement domain integrity, i.e., rules that govern
what the valid entries are in a table.
CHECK constraints limiting the values that are accepted by a column.
If you define a CHECK constraint on a single column it allows only
certain values for this column.
Ex: in an employee table, you may not want the employee age to be
less than 18 years or more than 65 years
CHECK constraint get executed when new record is inserted or to
update existing record.
A CHECK constraint returns TRUE when the condition is satisfied if it
is not it returns FALSE
When CHECK constraint returns TRUE only record inserted or
updated.
You can apply multiple CHECK constraints to a single column.
You can also apply a single CHECK constraint to multiple columns
Types of Keys
CREATE TABLE EmployeeDetails
(
EmpId INT,
Age TINYINT,
EmpName VARCHAR(50),
CONSTRAINT employee_ck01 CHECK (Age BETWEEN 18
AND 65)
)