[英]How to reset AUTO_INCREMENT for specific composite key (MyISAM)?
I like to set internal AUTO_INCREMENT counter for the table, which uses MyISAM and composite primary key - but just for specific PK combination.我喜欢为表设置内部 AUTO_INCREMENT 计数器,它使用 MyISAM 和复合主键 - 但仅用于特定的 PK 组合。 If I use如果我使用
ALTER TABLE tablename AUTO_INCREMENT = 1;
It will set internal counter for all composite PK combinations, which I don't want.它将为所有复合 PK 组合设置内部计数器,这是我不想要的。
I need something like我需要类似的东西
ALTER TABLE tablename AUTO_INCREMENT = 1 WHERE prefix = 5 AND suffix = X;
It does not work this way.它不会以这种方式工作。 Is there any possibility to change only counter for specific PK combination in MyISAM table?是否有可能仅更改 MyISAM 表中特定 PK 组合的计数器?
Table:桌子:
CREATE TABLE `ENG__faktury_counter`
(
`year` int(10) NOT NULL,
`prefix` varchar(10) NOT NULL,
`DIC` varchar(50) NOT NULL,
`id_counter` int(15) NOT NULL AUTO_INCREMENT ,
`created` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`year`,`prefix`,`DIC`,`id_counter`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8
There is virtually zero use for ALTER TABLE ... AUTO_INCREMENT=...
. ALTER TABLE ... AUTO_INCREMENT=...
使用几乎为零。
If you are using MyISAM and have如果您使用的是 MyISAM 并且有
foo ...
id ... AUTO_INCREMENT
PRIMARY KEY(foo, id) -- where the _2nd_ column is auto-inc
Then there is nothing to do to get然后没有什么可做的
foo id
--- --
cat 1
cat 2
dog 1
bird 1
cat 3
bird 2
bird 3
dog 2
regardless of the order in which you insert the rows.无论您插入行的顺序如何。
If this does not address your question, please enhance it with an example and SHOW CREATE TABLE
.如果这不能解决您的问题,请使用示例对其进行增强并SHOW CREATE TABLE
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.