
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How do I add a check constraint to a table in MySQL?
To add a check constraint to a table, let us first create a table.
CREATE table yourTableName ( Column_name1 datatyep, . . . . Column_name N datatype, check( condition) );
The following is how you can check the age by creating a check constraint.
check(Age>=45)
Let us now create a table and while creating a table, we will add the above shown check constraint for age.
mysql>CREATE table addCheckConstraintDemo -> ( -> Age int, -> check(Age>=45) -> ); Query OK, 0 rows affected (0.55 sec)
- Related Articles
- How do I remove a uniqueness constraint from a MySQL table?
- How can we check the indexes created by a UNIQUE constraint on a MySQL table?
- How can we add a FOREIGN KEY constraint to the field of an existing MySQL table?
- How do I detect if a table exist in MySQL?
- How do I alter a MySQL table column defaults?
- How do I add to each row in MySQL?
- How can we drop UNIQUE constraint from a MySQL table?
- Add a positive integer constraint to an integer column in MySQL?
- How add a unique key constraint to a column of a table in a database using JDBC API?
- How do I list all the columns in a MySQL table?
- How do I show unique constraints of a table in MySQL?
- How do I clone the structure of a table in MySQL?
- How to add a primary key constraint to a column of a table in a database using JDBC API?
- How to add a NOT NULL constraint to a column of a table in a database using JDBC API?
- How to add a column in a table in MySQL?

Advertisements