-1

I created a

CONSTRAINT chk_donate CHECK credit_card_no LIKE '[0-9][0-9][0-9][0-9][0-9][0-9][0-9]'

but with using an insert query to column name 'credit_card_no' with a numeric datatype with letters, there's no error and the value is 0. Please help.

4
  • 1
    Why don't you use an integer type for credit_card_no? Commented Jul 29, 2014 at 8:07
  • Just check it in PHP... Commented Jul 29, 2014 at 8:08
  • MySQL doesn't support constraints. Why are you using a non-numeric type to store numeric data anyway? Commented Jul 29, 2014 at 8:10
  • GordonM I was trying to check if the constraints was working. Commented Jul 29, 2014 at 9:31

2 Answers 2

6

Currently (MySQL 5.7.x) the CHECK clause is ignored by MySQL, see manual, CREATE TABLE:

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. I read that manual. Its really helpful.
0

This is because of your CHECK method.The latest versions of mysql uses CREATE TABLE method instead of CHECK..Changing CHECK to CREATE TABLE or you can use TRIGGER as mentioned here

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.