如果表是空的,你可能只是这样做:
ALTER TABLE mytable MODIFY COLUMN id bigint not null primary key auto_increment
,但我不知道会在这行发生什么。最好使用正确的定义创建一个新的数据库,通过减去id列来复制数据,删除旧的(错误的)表格,并将新数据移动到旧名称。
-- Either:
CREATE TABLE newtable LIKE mytable;
ALTER TABLE newtable MODIFY COLUMN id bigint not null primary key auto_increment;
-- or:
CREATE TABLE newtable (
id bigint not null primary key auto_increment,
column1 type1,
column2 type2,
...
);
INSERT INTO newtable
(column1, column2, ...)
SELECT column1, column2, column3, ...
FROM mytable;
-- Make SURE that insert worked BEFORE you drop the old table
-- and lose data if it didn't.
DROP TABLE mytable;
ALTER TABLE newtable RENAME TO mytable;
我相信phpMyAdmin有能力以图形方式做到这一点。
您有表的模式? –