1ALTER TABLE <table>
2ADD CONSTRAINT chk_val CHECK (col in ('yes','no','maybe'))
1CREATE TABLE test(
2 _id BIGINT PRIMARY KEY NOT NULL,
3 decision NVARCHAR(5),
4 CHECK (decision in ('yes','no','maybe'))
5);
1CREATE TABLE employee
2
3 ( employee_id VARCHAR(20),
4
5 Name VARCHAR (20),
6
7 Address VARCHAR (20),
8
9 Mobile_no SMALLINT);
10
1Adds a constraint that limits the value which can be added to a column.
2Example 1 (MySQL): Makes sure any users added to the users table are 18
3or over.
4CREATE TABLE users (
5first_name varchar(255),
6age int,
7CHECK (age>=18)
8);
9Example 2 (MySQL): Adds a check after the table has already been
10created.
11ALTER TABLE users
12ADD CHECK (age>=18);