Looping data in MySQL--build test data

Source: Internet
Author: User

Background description

Test requirements: For example, to filter by the number of pre-ordered organizations, ranked 51st and after the organization does not show.

Before verifying the function, there are at least 50 different appointments in the test data,

Implementation method:

1. Or manually inserted into the database table, 50 organizations to add a different number of appointments, to add, side record the number of appointments.

2. Generate data in a certain pattern and insert it into a database table.

3. Loop through the data with the SQL statement (find the rules in advance)

--------------------------------------------------------------------------------------------------------------- ------

Institution Reservation record form
Id+1 User ID can be unchanged mobile phone number can be unchanged agency ID (after adding the number of appointments to the organization, the organization ID to change, that is, to add the number of appointments to other organizations)
1 623182 15228*****64 1 0 0 2018-06-14 18:33:44 2 018-06-14 18:33:44


#DELIMITER # CREATE PROCEDURE test_fi () BEGIN DECLARE  ID int default  2384;            #主键 #declare  institition_id int  default 978; #机构id #declare  num int  default    ; #为N个机构创建预约记录, the number of appointments per institution is n#declare  temp int default 0;      #temp被赋值为N, create n number of appointments # #为N个机构创建预约记录 for your organization, with an appointment of N#while num>0 doset temp=num;while temp>0 doinsert into reservation per institution _apply values (ID, ' 722619 ', ' 13513111311 ', institition_id, ', ', ', 0, ', 0, ', ' 2018-6-30 14:47:51 ', ' 2018-6-30 14:47:58 ') ; set id=id+1; SET temp=temp-1;end While;set num=num-5; SET institition_id = institition_id-5; END while; END call Test_fi ();
# INSERT INTO reservation_apply values (2224, ' 722619 ', ' 13511111111 ', 100, ', ', ', 0, ' ', 0, ', ' 2018-6-30 14:47:51 ', ' 2018-6-30 14:47:55 '); The result of the operation is OK #

About MySQL stored procedures, this is the tip of the iceberg, but also continue to learn.

Test by the 1th way to build data, later in the 3rd way to build data, this contrast is too obvious, saving time and effort. ??

Looping data in MySQL--build test data

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.