开发者

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

I would like to create e.g. 1000 rows with the same values for each column in my table 开发者_如何学C(the only difference would be the autoincrement first id column), however I do not know how to write this mysql statement.

Any suggestion?


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);


i didn't know you could do that in MySQL but @nick rulez have better answer i guess , however this is how you can do it via 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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜