5
I ended up taking a table to manipulate, I noticed that sometimes the value of auto increment repeated, the first thing that called me the attention was that the key Primary was composed of two fields one of them was AI and the other not.
I set an example that reproduces this behavior:
CREATE TABLE t (
id int(11) NOT NULL AUTO_INCREMENT,
c2 varchar(45) NOT NULL,
c3 varchar(45) NOT NULL,
PRIMARY KEY (c2, id)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
Inserts
INSERT INTO t(c2, c3) VALUES ('A', 'A'), ('A', 'B'), ('B', 'A'), ('B', 'C'), ('C', 'A'), ('C', 'B'), ('A', 'C')
Select result:
# |id|c2|c3
1 |1 |A |A
2 |1 |B |A
3 |1 |C |A
4 |2 |A |B
5 |2 |B |C
6 |2 |C |B
7 |3 |A |C
What is the logic of auto increment when it is part of a composite primary key?
When you say "Innodb does not allow this type of construction" you refer to the composite key with one of the AI columns?
– Pedro Teles
@Exact Pedroteles, the error is returned:
Error Code: 1075. Incorrect table definition; there can be only one auto column and it must be defined as a key
– rray