Are SQL queries guaranteed to execute atomically when using UNION?

前端 未结 3 1520
夕颜
夕颜 2021-01-02 08:29

I am issuing a single SQL query consisting of multiple SELECTs grouped using UNION:

SELECT *
FROM   employee 
       LEFT JOIN department 
          ON emplo         


        
3条回答
  •  长情又很酷
    2021-01-02 09:07

    EDIT: Note that my answer is incorrect but I do not want to delete it because I think it links to good questions and has good comments.

    Every individual transaction is atomic.

    A UNION using multiple subqueries is a single T-SQL command, a single transaction, and will be atomic.

    This is, in part, a reason to avoid inefficient queries (or sprocs, for that matter) as their atomic nature can delay other transactions.

    EDIT: Please see this question for more interesting information on atomicity of subqueries

    Is update with nested select atomic operation?

    EDIT: Apparently I am wrong.

    This is a good discussion on the topic: Atomic UPSERT in SQL Server 2005 where Remus poses a good example. Sorry for doubting you, Martin....

提交回复
热议问题