Skip to content

Instantly share code, notes, and snippets.

@Dillie-O
Created November 4, 2015 12:49
Show Gist options
  • Save Dillie-O/50133cf07309d86872ee to your computer and use it in GitHub Desktop.
Save Dillie-O/50133cf07309d86872ee to your computer and use it in GitHub Desktop.
Fill a table sequentially with random data
drop procedure if exists load_table_test_data;
delimiter #
create procedure load_table_test_data()
begin
declare v_max int unsigned default 10;
declare v_counter int unsigned default 1;
declare v_min_rand int unsigned default 1;
declare v_max_rand int unsigned default 6;
truncate table job_category;
start transaction;
while v_counter < v_max do
INSERT INTO job_category (job_id, category_id)
VALUES (v_counter, FLOOR(v_min_rand + (RAND() * (v_max_rand - v_min_rand))) );
set v_counter=v_counter+1;
end while;
commit;
end #
delimiter ;
call load_table_test_data();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment