我正在尝试使用phpMyAdmin将十亿行插入到SQL表中但是我收到此错误:
Unrecognized statement type. (near "FOR" at position 0)
这是我的代码:
FOR @i in 1 ..1000000000 do
BEGIN
INSERT INTO test VALUES (@i, "First", "Second", "Long lorem ipsum here!")
END
我做错了什么?
答案 0 :(得分:2)
您需要一个程序来运行循环,如下面的代码所示:
DROP PROCEDURE IF EXISTS WhileLoop;
DELIMITER $$
CREATE PROCEDURE WhileLoop()
BEGIN
set @start = 0;
set @end = 1000000;
WHILE @start < @end
DO
# LOOP QUERY & INSERT NEW RECORD
INSERT INTO test VALUES (@start, "First", "Second", "Long lorem ipsum here!")
SET @start = @start + 1;
END WHILE;
END$$
call WhileLoop();
答案 1 :(得分:0)
使用While循环代替For,如下面的代码所示:
Set @i = 1
While(@i <=1000000000)
BEGIN
INSERT INTO test VALUES (@i, "First", "Second", "Long lorem ipsum here!");
set @i = @i+1;
END