Wrox Programmer Forums
BOOK: Beginning Database Design Solutions ISBN: 978-0-470-38549-4
This is the forum to discuss the Wrox book Beginning Database Design Solutions by Rod Stephens; ISBN: 9780470385494
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Database Design Solutions ISBN: 978-0-470-38549-4 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old May 2nd, 2012, 01:28 PM
Authorized User
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.

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

as well as

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..
Old May 2nd, 2012, 04:10 PM
Rod Stephens's Avatar
Wrox Author
Join Date: Jan 2006
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts

Sorry but both of those look valid to me. But I've seen some posts that say MySQL doesn't support CHECK constraints. See this thread:


Be sure to read the replies. They say you may be able to use a trigger to perform the job of the CHECK constraint.

In this case you could also build a lookup table and use it as a foreign key to validate the field. That seems like serious overkill but it should work.

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
The Following User Says Thank You to Rod Stephens For This Useful Post:
masterlayouts (May 3rd, 2012)

Similar Threads
Thread Thread Starter Forum Replies Last Post
Reference Constraint? jn148 BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 4 December 29th, 2008 10:06 AM
Can I have a constraint like this.....? callagga SQL Language 7 August 13th, 2008 01:08 AM
Error adding a check constraint SQLScott SQL Server 2005 2 October 3rd, 2007 05:58 AM
CHECK Constraint Error Kep SQL Server 2000 5 April 11th, 2006 08:46 PM
constraint for 1-to-n relation j_yan MySQL 0 December 10th, 2004 11:03 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.