How to use stored procedures in mysql & DataFactory prepares test data
Xiaobian to share with you how to use the storage process &DataFactory in mysql to prepare test data, I believe most people still do not know how, so share this article for your reference, I hope you have a lot of harvest after reading this article, let's go to understand it together!
Suppose we have the following 2 tables: student , detail_info. (MySQL version)
The foreign key of other detail_info is name (that is, the value of name in detail_tail should be in student)
Now you're ready to insert data into these two tables for testing,
Method 1: Manual insertion
You must choose to insert a record into student, and then insert another record into detail_info, and name must be present in student.
Method 2: Use MySQL stored procedures
2.1 Create stored procedures (insert data one at a time)
code block
create procedure pr_add
(
v_id int, --id to insert
v_name varchar(20) -name to insert
)
begin
INSERT INTO `student` VALUES (v_id, v_name, 'male', '20', '2011-08-16 22:05:45' );
INSERT INTO `detail_info` VALUES (v_id, v_name, '2011-08-16', '13881954050', 'xinjiang');
end;
2.2 call a stored procedure
Query the corresponding table check
1.3 Dig into one and create a stored procedure that inserts multiple pieces of data at once
code block
create procedure proc_add
(
int number--How many new pieces of data to insert
)
begin
declare v_name varchar(20);
declare v_i int;
set v_i=0;
select max(id) into v_i from student; --Get the maximum id in the current table and store it in variable v_i
set number=v_i+number; --max id
set v_i=v_i+1; --inserted id starts with current id+1
while v_i