Home > Database > Mysql Tutorial > MySQL与MSSQl使用While语句循环生成测试数据的代码

MySQL与MSSQl使用While语句循环生成测试数据的代码

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 18:02:59
Original
1338 people have browsed it

有时候我们测试性能的时候经常需要生产大量的测试数据,用sql语句直接生成的数据更快,需要的朋友可以参考下。

在MySQL中,使用While语句循环与SQL Server中有所不同,代码测试通过。

MSSQL中使用while语句循环生成数据的方法:

示例代码:
代码如下:
declare @a int
set @a = 1
while @abegin
INSERT INTO demotable (id,item1,item2) VALUES (@a,"abc","123")
set @a = @a + 1
end

MySQL中,使用while循环处理数据方法:需要新建为存储过程,直接调用执行存储过程。

示例代码:
代码如下:
CREATE DEFINER=`root`@`localhost` PROCEDURE `NewProcedure`()
BEGIN
DECLARE i INT;
SET i=1;
WHILE iINSERT INTO demotable (id,item1,item2) VALUES (i,"测试试题","0");
SET i = i + 1;
END WHILE;
END;
Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template