简体   繁体   English

如何使用InnoDB表类型完成此操作?

[英]How can this be done using an InnoDB table type?

I have the following code that uses a MyIsam table type because of see the comment in the create code. 我有以下使用MyIsam表类型的代码,因为请参见创建代码中的注释。 How can this be done using Innodb. 如何使用Innodb做到这一点。

Actually, a new article id is generated based on the user, and it starts from 1 for each user. 实际上,会根据用户生成新的商品ID,并且每个用户的商品ID从1开始。 However, this cannot be done if the table type is changed. 但是,如果更改了表类型,则无法完成此操作。 How can this be achieved when using INNODB? 使用INNODB时如何实现?

CREATE TABLE `articles` (
    `artcId` INT(10) NOT NULL AUTO_INCREMENT,
    `artcUserId` INT(10) NOT NULL DEFAULT '0',
    `artcTitle` VARCHAR(50) NOT NULL DEFAULT 'No title defined',
    `arctTime` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (`artcUserId`, `artcId`)// See this part here and see the Image below.
)
COLLATE='utf8_general_ci'
ENGINE=myisam;

屏幕截图

you can work with the trigger that is posted in the other thread or do it manually. 您可以使用其他线程中发布的触发器,也可以手动执行。

Pseudocode: 伪代码:

START TRANSACTION; -- needs to be in a transaction
...
SELECT @lastid := MAX(idItem) FROM item WHERE idArticulo = ?;
INSERT INTO item (idArticulo, idItem, texto)
VALUES (?, @lastid+1, ?);
...
COMMIT;

To handle the first-time situation:
MAX(idItem)
-->
IFNULL(MAX(idItem), 1)

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

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