mysql进阶篇之添加自增id列
作者:YXN-sql 阅读量:118 发布日期:2022-10-01
1、create语句添加
create table temp ( id int primary key auto_increment) AS (select * from a)
2、alter语句添加
alter table temp add id int primary key auto_increment;
3、UPDATE语句更新
-- UPDATE语句更新现有数据的id列为自增值:
SET @id := 0;
UPDATE temp SET id = @id := @id + 1;
YXN-sql
2022-10-01