将行号作为列包含在MySQL INSERT中 [英] Include row number as column in MySQL INSERT

查看:129
本文介绍了将行号作为列包含在MySQL INSERT中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以插入在MySQL中插入的行的行号吗?像这样:

Is there any way to insert the row number of a row as it is inserted in MySQL? Something like:

INSERT INTO users SET uid=ROWNUMBER(), email="joe@example.com";

如果没有,您是否建议采用其他方法根据条目号创建uid?

If not, is there any other way that you would suggest to create a uid based on the entry number?

谢谢!

推荐答案

MySQL(以及大多数RDBMS)没有任何内部行号或顺序.但是,您可以创建一个uid列,该列将在每次插入新记录时自动递增.

MySQL (along with most RDBMS) does not have any internal row number or order. However, you can create an uid column which will auto increment every time a new record is inserted.

ALTER TABLE users ADD uid INT NOT NULL AUTO_INCREMENT PRIMARY KEY

现在,当您执行INSERT时,MySQL将自动增加uid列.

Now when you do an INSERT, MySQL will automatically increment the uid column.

INSERT INTO users SET email="joe@example.com"

这篇关于将行号作为列包含在MySQL INSERT中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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