insert multiple data into mysql with while

Asked

Viewed 62 times

0

Good night, you guys!

created this code in order to insert 5 new users and passwords that follow a pattern PAM1 ... PAM5 and CP@M20161 ... CP@M20165,

CREATE PROCEDURE myfunction()
BEGIN
  DECLARE i INT DEFAULT 1;

  WHILE i < 6 DO
    INSERT INTO teste (userlogin, userpass) VALUES ("PAM" + i, MD5 ("CP@M2016" + i));
    SET i = i + 1;
  END WHILE;
END;

there is no syntax error, but it says that the process already exists... how to solve this problem, because the procedure will be made for 4000 inserts after you make it work... Thank you for your attention!

  • Delete the previous one before inserting one with the same name. A possible improvement would be to take the i of the autonumbering (or the largest existing ID), and use a parameter to tell how many inserts, so simply call the function whenever you want to add more N users (if you need this process again in the future, of course)

  • the problem is that there is no other... only this...

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.