在MySQL中插入序号 [英] Insert sequential number in MySQL

查看:376
本文介绍了在MySQL中插入序号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在表中添加了一个空列,现在我想在其行中插入序号.是否可以使用SQL做到这一点?

I added an empty column to a table and now I want to insert sequential numbers to its rows. Is it possible to do it using SQL?

推荐答案

运行以下查询以使yourField列中的值增加:

Run the following queries to have incremented value in yourField column:

SELECT @i:=0;
UPDATE yourTable SET yourField = @i:=@i+1;

这篇关于在MySQL中插入序号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆