与性能相关:插入多行SQL
是更好地使1000个查询,插入1000行:
for($i=1;$i<=1000;++$i){
$query = 'insert into table1 (First,Last) values ("Fred","Smith")';
mysql_query($query);
}
还是要使用PHP创建一个查询(在for循环串联值)像这样:
$query = ' insert into table1 (First,Last) values ("Fred","Smith"),
("John","Smith"),
...
("Michael","Smith"),
("Robert","Smith")';
mysql_query($query);
鉴于可能有很多值,我一次选择插入10个值。我不知道这没关系,在这种情况下最好的做法是什么?
但是,如果卡车不够大,无法安装所有这些箱子呢? :)(查询大小限制?) – Cristy
@Cristy然后将其分成包含每个框的最大数量的最小行程数。仍然快于1000次旅行。 –