Skip to content

Instantly share code, notes, and snippets.

@MacoTasu MacoTasu/test.sql
Created Dec 6, 2015

Embed
What would you like to do?
create test data sql
DROP TABLE IF EXISTS `entries`;
CREATE TABLE `entries` (
`id` INTEGER unsigned NOT NULL auto_increment,
`user_id` INTEGER,
`title` VARCHAR(191) NOT NULL,
`created_at` datetime,
`updated_at` datetime,
INDEX `user_id_idx` (`user_id`),
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARACTER SET utf8mb4;
INSERT INTO entries(user_id, title, created_at, updated_at) values(1, 'summer vacation', now(), now());
DROP PROCEDURE IF EXISTS create_dummy_entries;
DELIMITER //
CREATE PROCEDURE create_dummy_entries()
BEGIN
DECLARE counter INT DEFAULT 0;
WHILE counter < 20 DO
INSERT INTO entries(user_id, title, created_at, updated_at) SELECT user_id, title, created_at, updated_at FROM entries;
SET counter = counter + 1;
END WHILE;
END //
DELIMITER ;
CALL create_dummy_entries();
DROP PROCEDURE IF EXISTS create_dummy_entries;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.