Created
August 20, 2019 15:11
-
-
Save theothermattm/91e850598cb432fa210fff2bc0d8e3dd to your computer and use it in GitHub Desktop.
Create Dummy Data with MySQL Stored Proc
This file contains 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
/* based on https://stackoverflow.com/a/17268740/288935 */ | |
CREATE PROCEDURE insert_test_data() | |
BEGIN | |
DECLARE i INT default 1; | |
DECLARE mydate DATE DEFAULT NOW(); | |
SET mydate = DATE_ADD('2017-05-01 00:01:00', INTERVAL FLOOR(RAND() * 700) DAY); | |
WHILE i < 1000000 DO | |
INSERT INTO `telemetry_test` (`humidity`, `temperature`, `sql_insert`, `sql_update`) | |
select | |
FLOOR(RAND() * 40), FLOOR(RAND() * 80), mydate, mydate; | |
SET i = i + 1; | |
END WHILE; | |
END$$ | |
DELIMITER ; | |
CALL insert_test_data(); | |
DROP PROCEDURE insert_test_data; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Takes a while to run..