What's the meaning of this SQL statement?
I am new to SQL transction. What's the meaning 开发者_运维知识库of the following statement?
BEGIN TRAN
-- xlock the transaction
IF EXISTS (SELECT 1 FROM dbo.ActiveTransaction WITH (XLOCK) WHERE TransactionId = @transactionId)
BEGIN
(Omitted)
END
COMMIT TRAN
Thanks!
What's happening here is:
- A Sql Transaction is begun
- You check to see if the
dbo.ActiveTransaction
table contains a record whereTransactionId
is equal to the alue in the variable @transactionid.- If yes, you do the "(Omitted)" code
- Any changes made are COMMIT'ed to the database
The 'XLOCK' means that:
Specifies that exclusive locks are to be taken and held until the transaction completes. If specified with ROWLOCK, PAGLOCK, or TABLOCK, the exclusive locks apply to the appropriate level of granularity.
精彩评论