1

Another what I am sure is a very basic MySQL question.

Create Table MyTable 
(
    zip char(5) CHECK (zip = '11111')
);

Insert into MyTable
Select '99999';

SELECT * From MyTable;   --results in '99999'

I restrict 'zip' to only the value '11111', but it lets me put in '99999' no problem. What am I missing?

Bill Karwin
  • 538,548
  • 86
  • 673
  • 828
J Brun
  • 1,246
  • 1
  • 12
  • 18

1 Answers1

1

https://dev.mysql.com/doc/refman/5.6/en/create-table.html says:

The CHECK clause is parsed but ignored by all storage engines.

That is, it accepts the syntax without error or warning, but does not store the constraint and does not prevent you from inserting data that does not satisfy the check.

This feature has been requested since at least 2004, but never implemented: http://bugs.mysql.com/bug.php?id=3464

Bill Karwin
  • 538,548
  • 86
  • 673
  • 828