问题
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