RSS Feed

CHECK constraint

SQL CHECK constraint

The SQL CHECK constraint bounds/limits the value range that can be placed in a column.

For example, the range of values for a salary column can be limited by creating a CHECK constraint that allows for only data that ranges from $15,000 through $100,000. This prevents salaries from being entered beyond the regular salary range.

Example of SQL CHECK constraint

The following SQL query creates a CHECK constraint on the "Emp_ID" column when the "Employees" table is created. The CHECK constraint specifies that the column "Emp_ID" must only include integers greater than 0.


CREATE TABLE Employees
(
Emp_ID int NOT NULL CHECK (Emp_ID>0),
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Address varchar(255)
)

No comments:

Post a Comment