Mysql and MSSQL code to generate test data using the while statement _mysql

Source: Internet
Author: User
Tags mssql
In MySQL, the code test passes with a while statement loop that differs from SQL Server.

Method of using the while statement to generate data in MSSQL:

Sample code:
Copy Code code as follows:

DECLARE @a int
Set @a = 1
While @a<25
Begin
INSERT into Demotable (id,item1,item2) VALUES (@a, "abc", "123")
Set @a = @a + 1
End

In MySQL, use a while loop to process data methods: You need to create a new stored procedure to call the Execute stored procedure directly.

Sample code:
Copy Code code as follows:

CREATE definer= ' root ' @ ' localhost ' PROCEDURE ' newprocedure ' ()
BEGIN
DECLARE i INT;
SET I=1;
While i<100 do
INSERT into Demotable (id,item1,item2) VALUES (i, "Test questions", "0");
SET i = i + 1;
End while;
End;
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.