January 1, 2021

#94 - MySQL how to add, remove and check a constraint in a table

In this post is shown a simple example about how to add, remove and check a constraint in a MySQL table. In this case the constraint is that the grade field is a INT value between 0 and 10.
Describing the table and checking the table details:

Note: If the table has already some rows that violates the new added constraint, the execution of the command above will fail and the following message is displayed:

Now inserting some values into the table, and showing how trying to violate the constraint will generate an error:

Checking that the constraint has been correctly added to the table:

To delete a constraint:

No comments:

Post a Comment