How to create 1000 rows with the same values ​​in columns?

I would like to create, for example. 1000 rows with the same values ​​for each column in my table (the only difference would be in the column of the first auto-increment identifier), however I do not know how to write this mysql statement.

Any suggestion?

+5
source share
2 answers
create table mytest (
id int not null auto_increment primary key,
col1 varchar(10),
col2 varchar(10)
) engine = myisam;

delimiter //
create procedure populate (in num int)
begin
declare i int default 0;
while i < num do
insert into mytest (col1,col2) values ('col1_value','col2_value');
set i = i + 1;
end while;
end //
delimiter ;

call populate (1000);
+10
source

I did not know that you can do this in MySQL, but @nick rulez is better to answer, I think, however this is how you can do it through PHP.

$host = 'localhost';
$username = 'myusername';
$password = 'mypassword';
$connect = mysql_connect($host, $username, $password);

for($i=0; $i<=1000; $i++) {
   $query = 'INSERT INTO tablename(column1, column2, column3) VALUES (value1, value2, value3)';
   mysql_query($query);
}
0
source

All Articles