I have a small SQL script:
SET @userId=12345;
SET @roleId=5;
BEGIN;
INSERT INTO mydatabase.Users(userId, roleId) VALUES (@userId, @roleId);
COMMIT;
I am looking to run this same script, but for a specific list of userId
s, like this pseudocode:
SET @userIdList=[12345, 23456, 34567];
SET @roleId=5;
FOR EACH id in @userIdList:
BEGIN;
INSERT INTO mydatabase.Users(userId, roleId) VALUES (@userId, @roleId);
COMMIT;
END
What is the correct syntax to do something like this in MySQL?