加入联合查询需要交易吗? [英] Do i need transaction for joined query?

查看:54
本文介绍了加入联合查询需要交易吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在执行带有联接的sql查询期间,我需要使用事务吗?

During sql queries with joins, do i need to use transactions?

我在想类似的东西:

Delete table1, table2, table3 
FROM table1 INNER JOIN table2 ON(...) 
LEFT JOIN table3 ON (...) 
WHERE table1.column = something...

(我不知道语法是否100%正确,但我想您还是理解的)

(I dont know if the syntax is 100% correct, but i guess that you understand it anyway)

是否存在并非所有应删除的行都不会被删除的风险?

Is there any risk that not all rows that should be deleted doesnt get deleted?

谢谢!

推荐答案

由于这是单个命令(DELETE),因此无需显式使用事务.根据定义,SQL命令是原子的,即它将删除所有符合条件的行,或者根本不删除任何行.

Since this is a single command (DELETE) there's no need to explicitly use a transaction. SQL commands are atomic by definition, i.e. it will either delete all the rows that match the criterion or none at all it there is an error.

此答案在理论上和对于支持ACID的数据库都是正确的.如果数据库不支持原子性,或者存在一些错误会触发数据库引擎方面的错误行为,那么所有选择都将关闭.但是,在这种情况下,使用事务进行魔术般的改进不太可能.

This answer is correct in theory, and for databases that support ACID. If the databases do not support atomicity, or there are bugs that trigger incorrect behaviour on the part of the database engine, all bets are off. However, it's unlikely that using transactions will magically make it better in those scenarios.

这篇关于加入联合查询需要交易吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆