求助!mysql自增长列出现问题
表中删除大量记录后,自增长列出现递减,这是什么情况,联合主键,用的delete from 删除
------解决方案--------------------
MYSQL 中当auto_increment 为复合主键之一时,基增长规则不同。建议参考MYSQL官方免费手册中的例子以便理解。
CREATE TABLE animals (
grp ENUM('fish','mammal','bird') NOT NULL,
id MEDIUMINT NOT NULL AUTO_INCREMENT,
name CHAR(30) NOT NULL,
PRIMARY KEY (grp,id)
) ENGINE=MyISAM;
INSERT INTO animals (grp,name) VALUES
('mammal','dog'),('mammal','cat'),
('bird','penguin'),('fish','lax'),('mammal','whale'),
('bird','ostrich');
SELECT * FROM animals ORDER BY grp,id;
Which returns:
+--------+----+---------+
| grp | id | name |
+--------+----+---------+
| fish | 1 | lax |
| mammal | 1 | dog |
| mammal | 2 | cat |
| mammal | 3 | whale |
| bird | 1 | penguin |
| bird | 2 | ostrich |
+--------+----+---------+
------解决方案--------------------联合主键,自增长列不放在第一位的原因。