一开始建的A表主键不是自增的id,现在需要新添加一个自增的id字段,直接执行以下语句是报错的:
[42000][1075] Incorrect table definition; there can be only one auto column and it must be defined as a key.
ALTER TABLE `A`
ADD COLUMN `id` bigint(11) NOT NULL AUTO_INCREMENT FIRST;
CREATE UNIQUE INDEX A_uindex
on `A` (`id`);
需要在一个SQL中执行:
ALTER TABLE `A`
ADD COLUMN `id` bigint(11) NOT NULL AUTO_INCREMENT FIRST,
ADD UNIQUE INDEX `A` (`id`),
AUTO_INCREMENT=1;