添加许多具有递增值的行。 (填下来?)

发布于 2024-12-03 13:10:33 字数 155 浏览 5 评论 0原文

我想向 MySQL 表添加 10,000 行。该表有一个字段,我们称之为“Number”,需要从 540000 增加到 549999。

这只是需要运行一次的内容,因此性能并不重要。是否有 MySQL 命令可以执行此操作,或者我是否需要编写一个脚本来调用 10,000 个插入语句?

I want to add 10,000 rows to a MySQL table. The table has a field, let's call it "Number", that needs to increment from 540000 to 549999.

This is just something that needs to run once, so performance is not critical. Is there a MySQL command that will do this, or do I need to write a script to call 10,000 insert statements?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烟火散人牵绊 2024-12-10 13:10:33

假设您在制表符分隔的文件中有这 10,000 行,您可以将数据批量加载到表中并逐步设置 Number 值,如下所示:

set @number = (540000 - 1);

load data infile '/tmp/your_data.txt' 
ignore into table your_table 
(column_1,...,column_n) 
set Number = (@number := @number + 1);

Assuming you have those 10,000 rows in a tab-delimited file, you can bulk load the data into your table and set the Number value incrementally like this:

set @number = (540000 - 1);

load data infile '/tmp/your_data.txt' 
ignore into table your_table 
(column_1,...,column_n) 
set Number = (@number := @number + 1);
凉城 2024-12-10 13:10:33

我最终创建了一个包含 10,000 个插入语句的脚本。

I ended up creating a script with 10,000 insert statements.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文