Does SQL Server acquire locks even without an explicit transaction?

拟墨画扇 提交于 2020-02-24 09:22:11

问题


I was reading about MSSQL Locking for the first time, and it many places, the locking mechanism concepts depend on the existence of Transactions. I was wondering whether locking (in general) is possible without having any Transactions involved?


回答1:


When no explicit transaction exists, each SQL statement is executed in an automatic (autocommit) transaction. Normal locking behavior will apply in that case and the locks released when the automatic transaction is completed as the statement completes.




回答2:


Yes. Under several isolation levels, including the default READ COMMITTED, queries take shared (S) locks, which will block the locks required to change data.

Every UPDATE, INSERT, DELETE, and MERGE runs in a single-statement transaction, even if you don't explicitly start a transaction via BEGIN TRANSACTION.



来源:https://stackoverflow.com/questions/48806983/does-sql-server-acquire-locks-even-without-an-explicit-transaction

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!