Mysql,有没有一种简单的方法来创建一个包含 500000(虚拟/零/空)行的表 [英] Mysql, is ther an easy way to create a table with 500000 (dummy/zero/empty) rows

查看:52
本文介绍了Mysql,有没有一种简单的方法来创建一个包含 500000(虚拟/零/空)行的表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 sql 数据库已经有一段时间了,但到目前为止我发现的强大的可能性给我留下了深刻的印象.

I've been working with sql databases just for a little time but I'm impressed of the powerful possibilities that I discovered so far.

现在我想做一些听起来很简单的事情,但我找不到简单的方法来解决它:
只需创建一个新表,假设有 500000 行并自动编号(ID).

Now I want to do something that sounds so easy but I was not able to find an easy way to solve it:
Just create a new table with let's say 500000 rows and get them numbered automatically (ID).

使用 PHP 可能是一个简单的循环,但我想知道是否真的需要使用 PHP.

Using PHP it's probably a simple loop but I wonder if it is really necesary to use PHP.

我几乎可以肯定有一个使用 mysql 命令甚至 phpMyAdmin 的简单解决方案.

I am almost sure there is a simple solution using a mysql command or even with phpMyAdmin.

推荐答案

无条件加入任意两个表,结果行数将相乘.使用局部变量增加该结果中每个选择的 id.

Join any two tables without condition and the resulting number of rows will be multiplied. Increase the id on every select from that result using a local variable.

这将创建大约 100 万行 (2^20);

This creates about 1M rows (2^20);

set @i = 0;
drop TEMPORARY table if exists dummyids;
create TEMPORARY table dummyids
    select @i := @i + 1 as id
    from (select true union all select true) t0
    join (select true union all select true) t1
    join (select true union all select true) t2
    join (select true union all select true) t3
    join (select true union all select true) t4
    join (select true union all select true) t5
    join (select true union all select true) t6
    join (select true union all select true) t7
    join (select true union all select true) t8
    join (select true union all select true) t9
    join (select true union all select true) t10
    join (select true union all select true) t11
    join (select true union all select true) t12
    join (select true union all select true) t13
    join (select true union all select true) t14
    join (select true union all select true) t15
    join (select true union all select true) t16
    join (select true union all select true) t17
    join (select true union all select true) t18
    join (select true union all select true) t19
;
select * from dummyids;

这篇关于Mysql,有没有一种简单的方法来创建一个包含 500000(虚拟/零/空)行的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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