如果表是空的,你可能只是這樣做:
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有能力以圖形方式做到這一點。
您有表的模式? –