Add a primary key column in to a no primay key old table

后端 未结 2 709
失恋的感觉
失恋的感觉 2021-01-04 02:56

If a table, data might be duplicated amount rows, and there is not primary key for every row,

can i add an column to be a primary key?

2条回答
  •  悲&欢浪女
    2021-01-04 03:21

    Yes. Add a new column and set it as the primary key with AUTO_INCREMENT. Doing so will create a new column and automatically add a unique id for each row.

    ALTER TABLE old_table ADD pk_column INT AUTO_INCREMENT PRIMARY KEY;
    

提交回复
热议问题