The following SQL code creates two tables, (A) __tableA__
, (B) __tableB__
. Both tables contain exactly 2 unique keys, named k1
and k2
.
SHOW VARIABLES WHERE Variable_name = 'version'; # 5.0.51b
CREATE TABLE __tableA__ (`a` INT, `b` INT,
UNIQUE KEY `k1`(`a`),
UNIQUE KEY `k2`(`a`,`b`)
); # Key_name Column_name
# -------------------------
SHOW KEYS FROM __tableA__; # k1 a
# k2 a
# k2 b
CREATE TABLE __tableB__ (`a` INT,
UNIQUE KEY `k1`(`a`),
UNIQUE KEY `k2`(`a`)
); # Key_name Column_name
# -------------------------
SHOW KEYS FROM __tableB__; # k1 a
# k2 a
DROP TABLE __tableA__; # cleanup
DROP TABLE __tableB__; #
As shown by the SHOW KEYS
command, the sets of attributes (columns) of keys k1
and k2
are
- A:
{a}
and{a,b}
, respectively, - B:
{a}
and{a}
, respectively.
This suggests the conclusion that, in MySQL, the concept of unique key does NOT correspond to either of the concepts of candidate key / superkey:
In case (A), k1
and k2
cannot be candidate keys because {a} ⊂ {a,b}
(thus the set of attributes of k2
is not minimal).
In case (B), k1
and k2
cannot be superkeys because they are different keys with identical sets of attributes.
My question: Is this conclusion correct? If so, which authoritative source does state it clearly?