简体   繁体   English

INNODB Engine中的Mysql AUTO_INCREMENT作为第二列

[英]MySql AUTO_INCREMENT in INNODB Engine as second column

i have a very annoying problem at this moment. 我现在有一个非常烦人的问题。 i want a table with the following specification: 我想要一张具有以下规格的表:

CREATE TABLE  `test` (
   `client` INT NOT NULL ,
   `id` INT NOT NULL AUTO_INCREMENT ,
   `test` INT NOT NULL ,
   PRIMARY KEY (  `client` ,  `id` ) ,
   INDEX (  `test` )
) ENGINE = INNODB;

you can see, that i have a primary key with 2 columns. 您可以看到,我有一个带有2列的主键。 now i want that the id auto_increment column only increments in order to the first column. 现在我希望id auto_increment列仅按顺序增加到第一列。 for example: 例如:

## client/id ##
1/1 
1/2 
1/3
2/1
2/2
2/3

etc. 等等

is this really impossible with innodb? innodb真的不可能吗? i need innodb because of the transactional features. 由于事务功能,我需要innodb。

You can derive it easily in SELECT statement 您可以在SELECT语句中轻松导出它

set @sno:=0;
set @client:='';
select @sno:=case when @client=client then @sno+1 else 1 end as sno,
@client:=client as client_id from table order by client;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM