WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

SQL CHECK Constraint


SQL CHECK Constraint

CHECK constraint is utilized to restrain the esteem extend that can be set in a column.


SQL CHECK Constraint on CREATE TABLE

The following SQL makes a CHECK limitation on the "User_Id" section when the "Persons" table is made. The CHECK limitation determines that the segment "User_Id" should just incorporate whole numbers more prominent than 0.

MySQL:

Make TABLE Persons
(
User_Id int NOT NULL,
Username varchar(255) NOT NULL,
Secret word varchar(255),
email varchar(255),
Telephone varchar(255),
CHECK (User_Id>0)
)

SQL Server/Oracle/MS Access:

Make TABLE Persons
(
User_Id int NOT NULL CHECK (User_Id>0),
Username varchar(255) NOT NULL,
Secret word varchar(255),
email varchar(255),
Telephone varchar(255)
)

To permit naming of a CHECK requirement, and for characterizing a CHECK limitation on various sections, utilize the accompanying SQL syntax:

MySQL/SQL Server/Oracle/MS Access:

Make TABLE Persons
(
User_Id int NOT NULL,
Username varchar(255) NOT NULL,
Secret word varchar(255),
email varchar(255),
Telephone varchar(255),
Requirement chk_Person CHECK (User_Id>0 AND Phone='Sandnes')
)

SQL CHECK Constraint on ALTER TABLE

To make a CHECK requirement on the "User_Id" section when the table is as of now made, utilize the accompanying SQL:

MySQL/SQL Server/Oracle/MS Access:

Modify TABLE Persons
Include CHECK (User_Id>0)

To permit naming of a CHECK limitation, and for characterizing a CHECK requirement on numerous sections, utilize the accompanying SQL syntax:

MySQL/SQL Server/Oracle/MS Access:

Adjust TABLE Persons
Include CONSTRAINT chk_Person CHECK (User_Id>0 AND Phone='Sandnes')

To DROP a CHECK Constraint

To drop a CHECK imperative, utilize the accompanying SQL:

SQL Server/Oracle/MS Access:

Adjust TABLE Persons
DROP CONSTRAINT chk_Person

MySQL:

Adjust TABLE Persons
DROP CHECK chk_Person