是否可以在phpmyadmin中一起执行两个更新查询?
同样聪明
UPDATE jos_menu SET home = 0 WHERE 1;
UPDATE jos_menu SET home = 1 WHERE id = 9;
现在我们可以将这两个查询一起复制并在phpmyadmin sql查询面板上运行吗? 它会被执行吗?
答案 0 :(得分:24)
是的,两个查询都将被执行。您可能添加的唯一附加内容是transaction。多亏了你,你将确保两个查询都成功执行:
START TRANSACTION;
UPDATE jos_menu SET home = 0 WHERE 1;
UPDATE jos_menu SET home = 1 WHERE id = 9;
COMMIT;
答案 1 :(得分:3)
update jos_menu set home=case id when 9 then 1 else 0 end
这将更新所有行,将1设置为id = 9的所有行,将0设置为其余行
答案 2 :(得分:0)
如果您不确定某些SQL是否会破坏您的实时网站并且您没有开发服务器,请复制数据库表并对其进行测试。
CREATE TABLE jos_menu_test LIKE jos_menu;
INSERT jos_menu_test SELECT * FROM jos_menu;
答案 3 :(得分:0)
基于@crozin回答,我做了以下查询:
START TRANSACTION;
SELECT id into @idTech FROM `team` WHERE abbr = 'D19';
delete from team_dayoff where team_id = @idTech;
delete from team_layer_lease where team_id = @idTech;
delete from team_product_linker where team_id = @idTech;
delete from team where id = @idTech;
COMMIT;