如何在MySQL中插入多行 [英] How to insert multiple rows into MySQL
问题描述
我是MySQL的新手(刚刚使用SQL Server),我想知道如何轻松地创建多行!
I am new to MySQL (have just been using SQL Server) and I am wondering how to create multiple rows easily!
我希望创建大约300行,因此我在网上找到的方法似乎还不够实用..
I am looking to create about 300 rows, so the methods I have found online just don't seem practical enough..
使用SQL Server时,您可以只使用GO语句,然后输入一个数字,它将多次运行该命令,例如:GO 50
When using SQL Server, you can just use a GO statement, and then enter a number afterwards and it will run the command that many times, such as : GO 50
在MySQL上有什么简单的方法吗?我已经阅读过有关使用循环语句的信息,但是找不到有关它的任何信息?
Is there anything as simple as this on MySQL? I have read about using a loop statement, but I cannot find any info on it?
任何帮助将不胜感激!
谢谢
-利亚姆.
推荐答案
不使用循环:
CREATE TABLE noderedtest(Password TEXT, Email TEXT);
INSERT INTO noderedtest (Password, Email) -- storing password in clear text
-- is very bad idea
WITH RECURSIVE cte AS
(
SELECT 1 AS i
UNION ALL
SELECT i+1
FROM cte
WHERE i < 300
)
SELECT 'Test', 'email@email.com'
FROM cte;
SELECT * FROM noderedtest;
DBFiddle Demo MySQL 8.0+
这篇关于如何在MySQL中插入多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!