If we want to remove a CHECK constraint from a table, but we don’t want to drop the table or column, we can use the ALTER TABLE statement with DROP CHECK.
Once the constraint has been dropped, data can be entered into the table without having to conform to the rules of the CHECK constraint.
Syntax
The syntax for dropping a CHECK constraint in MySQL goes like this:
ALTER TABLE <table_name>
DROP CHECK symbol;
Where symbol is the name of the CHECK constraint to drop.
Example
Suppose we create a table with a CHECK constraint like this:
CREATE TABLE Products (
ProductId int,
ProductName varchar(255),
ProductPrice decimal(8,2),
CONSTRAINT ProductPrice_chk CHECK (ProductPrice > 0)
);
This created a table with a CHECK constraint called ProductPrice_chk.
We can drop this CHECK constraint like this:
ALTER TABLE Products
DROP CHECK ProductPrice_chk;
That’s all. The CHECK constraint has now been dropped.
Now that it’s been dropped, data can enter the table without having to conform to the CHECK constraint.