Yii实现了如下的批量插入方式,如果是批量更新Yii2有没有相同的实现方式呢?
Yii::$app->db
->createCommand()
->batchInsert($table, $columns, $rows)
->execute();
批量更新是使用一条SQL语句实现批量更新,而非循环的更新的方式,e.g:
UPDATE order
SET field = CASE order_no
WHEN 1 THEN 'value'
WHEN 2 THEN 'value'
WHEN 3 THEN 'value'
END
WHERE order_no IN (1,2,3)
4 回答
![?](http://img1.sycdn.imooc.com/533e4d5b0001d57502200203-100-100.jpg)
慕盖茨4494581
TA贡献1850条经验 获得超11个赞
(Update t_user set name='aa' where 1=1)a union ALL
(Update t_user set name='bb' where 1=2)a union ALL
(Update t_user set name='cc' where 1=3)a union ALL
合并sql语句, 用循环字符串,组成一条SQL语句,一次执行,提高sql的效率。循环的效率,就用不了多少了比起sql
![?](http://img1.sycdn.imooc.com/54585094000184e602200220-100-100.jpg)
墨色风雨
TA贡献1853条经验 获得超6个赞
Yii::$app->db
->createCommand()
->batchInsert($table, $columns, $rows)
->execute();
同意这个
- 4 回答
- 0 关注
- 1279 浏览
添加回答
举报
0/150
提交
取消