我可以在一个查询中执行mysql选择,更新和删除吗? [英] Can I do a mysql Select, Update and Delete in one query?
问题描述
我可以说优化mysql的许多方法之一是减少查询数量吗?
Can I say that one of many ways to optimize mysql is to reduce the number of queries?
如果是这样,我可以这样做吗?
If that so, can I do this:
- Select "data" => $A from table X
- Update $A from table Y
- Delete $A from table X
在一个查询中?
推荐答案
您不能减少查询的数量-它们都做不同的事情-但您可以减少往返数据库的次数和解析的次数通过将它们全部包装为PLSQL函数.
You can't reduce the number of queries - they all do different things - but you could reduce the number of round trips to the database and the number of parses by wrapping it all as a PLSQL function.
但是,删除数据后,您将无法选择数据.....但请考虑:
However you can't select the data after you've deleted it.....but consider:
CREATE PROCEDURE s_u_d(a)
BEGIN
UPDATE tab_x SET tab_x.avalue=1 WHERE tab_x.another=a;
DELETE FROM tab_y WHERE tab_y.avalue=a;
SELECT *
FROM tab_x
WHERE tab_x.another=a;
END;
NB-您还可以在同一过程中运行多个选择,并处理多个不同形状的结果集,例如请参阅本页
NB - you can also run multiple selects in the same procedure and handle multiple, different shaped result sets, e.g. see this page
这篇关于我可以在一个查询中执行mysql选择,更新和删除吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!