Created
November 4, 2015 12:49
-
-
Save Dillie-O/50133cf07309d86872ee to your computer and use it in GitHub Desktop.
Fill a table sequentially with random data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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