using check contraint in MySQL for controlling string length not working

Posted by ptrn on Stack Overflow See other posts from Stack Overflow or by ptrn
Published on 2010-06-12T01:20:15Z Indexed on 2010/06/12 1:22 UTC
Read the original article Hit count: 353

Filed under:
|

Dear stackoverflow, I'm tumbled with a problem!

I've set up my first check constraint using MySQL, but unfortunately I'm having a problem. When inserting a row that should fail the test, the row is inserted anyway.

The structure:

CREATE TABLE user (
  id INT UNSIGNED NOT NULL AUTO_INCREMENT,
  uname VARCHAR(10) NOT NULL,
  fname VARCHAR(50) NOT NULL,
  lname VARCHAR(50) NOT NULL,
  mail VARCHAR(50) NOT NULL,
  PRIMARY KEY (id),
  CHECK (LENGTH(fname) > 3)
);

The insert statement:

INSERT INTO user VALUES (null, 'user', 'Fname', 'Lname', '[email protected]');

I'm pretty sure I'm missing something basic here.

© Stack Overflow or respective owner

Related posts about mysql

Related posts about mysql-query