MySQL unique clustered constraint not constraining as expected
Posted
by igor
on Stack Overflow
See other posts from Stack Overflow
or by igor
Published on 2010-03-26T02:50:21Z
Indexed on
2010/03/26
2:53 UTC
Read the original article
Hit count: 431
I'm creating a table with:
CREATE TABLE movies
(
id INT AUTO_INCREMENT PRIMARY KEY,
name CHAR(255) NOT NULL,
year INT NOT NULL,
inyear CHAR(10),
CONSTRAINT UNIQUE CLUSTERED (name, year, inyear)
);
(this is jdbc SQL)
Which creates a MySQL table with a clustered
index, "index kind" is "unique", and spans the three clustered columns:
However, once I dump my data (without exceptions thrown), I see that the uniqueness constraint has failed:
SELECT * FROM movies
WHERE name = 'Flawless' AND year = 2007 AND inyear IS NULL;
gives:
id, name, year, inyear
162169, 'Flawless', 2007, NULL
162170, 'Flawless', 2007, NULL
Does anyone know what I'm doing wrong here?
© Stack Overflow or respective owner