View Single Post
  #1 (permalink)  
Old May 2nd, 2012, 01:28 PM
masterlayouts masterlayouts is offline
Authorized User
Points: 143, Level: 2
Points: 143, Level: 2 Points: 143, Level: 2 Points: 143, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2012
Posts: 32
Thanks: 9
Thanked 0 Times in 0 Posts
Default CHECK constraint

I have a problem with CONSTRAINTs
This is what I am using:

mysql> SHOW VARIABLES LIKE "%version%";
+-------------------------+------------------------------+
| Variable_name | Value |
+-------------------------+------------------------------+
| innodb_version | 1.1.8 |
| protocol_version | 10 |
| slave_type_conversions | |
| version | 5.5.16 |
| version_comment | MySQL Community Server (GPL) |
| version_compile_machine | x86 |
| version_compile_os | Win32 |
+-------------------------+------------------------------+

I tried to add a CHECK constraint for the gender. I tried both these and without success. I saw a lot of people report it as a bug, but not sure if it's a but or I do something wrong.

Code:
CHECK(gender IN ('M', 'F'));
CHECK (gender LIKE '[MF]');
I tried

Quote:
ALTER TABLE users
ADD CONSTRAINT CHECK (gender LIKE '[MF]')
as well as

Code:
CONSTRAINT ck_gender CHECK (gender in ( 'M', 'F' ) )
when define the table.

Is my syntax wrong? Thank you for your time.

Last edited by masterlayouts; May 2nd, 2012 at 01:31 PM..