I am using MySQL Workbench. I am trying to build a table with random dummy data that I am generating using a loop. I want to loop through 100 columns which are named 1-100. How can this be accomplished?
Here is what I have so far. I get Error Code: 1054 Unknown column ‘count’ in ‘field list’.
DELIMITER $$
DROP PROCEDURE IF EXISTS insertUsingLoop3$$
CREATE PROCEDURE insertUsingLoop3()
BEGIN
DECLARE count INT DEFAULT 0;
DECLARE randValue INT DEFAULT 33;
WHILE count < 101 DO
SET randValue = FLOOR( RAND() * (127-33) + 33);
INSERT INTO test1(count)
VALUES(CHAR(randValue));
SET count = count + 1;
END WHILE;
END$$
DELIMITER ;
I was hoping to use the variable – ‘count’ as the column name since I named 100 columns using the numbers 1 – 100.
2
Answers
Using PHP with WAMP I was able to figure out a solution to what I was trying to do. Here is what I came up with.
You can create a query as a string and then execute it.
In your case, the query may be as follows: