4

For testing the TTFB for single pages loaded by a CMS I wan't to add new pages into my database without doing it one for one inside a CMS. For example I wan't to execute the query as below a 100 times inside a table, but how can I do this in mySql/phpmyadmin?

This query must be execute for 100 times

INSERT INTO `bolt_pages` (`id`, `slug`, `datecreated`, `datechanged`, `datepublish`, `datedepublish`, `username`, `ownerid`, `status`, `templatefields`, `title`, `image`, `teaser`, `body`, `template`) VALUES (NULL, 'hello-world', '2017-05-15 12:01:35', '2017-05-15 13:22:43', '2017-05-15 12:01:13', NULL, '', '1', 'published', '[]', 'Hello world', NULL, '<p>teaser</p>\r\n', '<p>Hello world</p>\r\n', '');
CodeWhisperer
  • 1,143
  • 2
  • 19
  • 39

2 Answers2

6

With a procedure should be...

DELIMITER $$
CREATE PROCEDURE simple_loop ( )
BEGIN
  DECLARE counter BIGINT DEFAULT 0;

  my_loop: LOOP
    SET counter=counter+1;

    IF counter=100 THEN
      LEAVE my_loop;
    END IF;

    #SELECT counter; #uncomment if you'd like to print the counter

    INSERT INTO `bolt_pages` (`id`, `slug`, `datecreated`, `datechanged`, `datepublish`, `datedepublish`, `username`, `ownerid`, `status`, `templatefields`, `title`, `image`, `teaser`, `body`, `template`) VALUES (NULL, 'hello-world', '2017-05-15 12:01:35', '2017-05-15 13:22:43', '2017-05-15 12:01:13', NULL, '', '1', 'published', '[]', 'Hello world', NULL, '<p>teaser</p>\r\n', '<p>Hello world</p>\r\n', '');

  END LOOP my_loop;
END$$
DELIMITER 
javier_domenech
  • 5,995
  • 6
  • 37
  • 59
1

You can use Repeat , or you can create a procedure as well:

SET @K = 0;
    lab1: REPEAT
    INSERT INTO `bolt_pages` (`id`, `slug`, `datecreated`, `datechanged`, `datepublish`, `datedepublish`, `username`, `ownerid`, `status`, `templatefields`, `title`, `image`, `teaser`, `body`, `template`) VALUES (NULL, 'hello-world', '2017-05-15 12:01:35', '2017-05-15 13:22:43', '2017-05-15 12:01:13', NULL, '', '1', 'published', '[]', 'Hello world', NULL, '<p>teaser</p>\r\n', '<p>Hello world</p>\r\n', '');
    Set @k = @k +1;
    UNTIL @K > 100 END REPEAT lab1;
Ilyes
  • 14,640
  • 4
  • 29
  • 55