MySQL and MSSQl use the While statement to generate test data code cyclically

Source: Internet
Author: User

In MySQL, The While statement loop is different from that in SQL Server, and the code passes the test.

In MSSQL, The while statement is used to generate data cyclically:

Sample Code:
Copy codeThe Code is 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, The while loop is used to process data: You need to create a stored procedure and directly call and execute the stored procedure.

Sample Code:
Copy codeThe Code is as follows:
Create definer = 'root' @ 'localhost' PROCEDURE 'newprocedure '()
BEGIN
DECLARE I INT;
SET I = 1;
WHILE I & lt; 100 DO
Insert into demotable (id, item1, item2) VALUES (I, "Test Question", "0 ");
SET I = I + 1;
End while;
END;

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.