MySQL 添加序号列

MySQL 添加序号列,第1张

alter table abc add num int unsigned auto_increment

如果同时为主键的话,可以这样写

alter table abc add num int unsigned primary key auto_increment

__________________________________________

to:数据库强者 不ok

alter table abc change num num int primary key auto_increment

前提是你的表中不能存在主键,否则请使用:

alter table abc change num num int auto_increment

一般情况下增长都是主键

select a.*,

(select count(*) from tbl where col<=a.col) as rownum

from tbl a

mysql 没有oracle里面的rownum函数,用这个sql可以模拟下,但是如果数据量大的话,可能执行很慢。


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/bake/11361553.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-15
下一篇 2023-05-15

发表评论

登录后才能评论

评论列表(0条)

保存