开发者

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:

  1. A Sql Transaction is begun
  2. You check to see if the dbo.ActiveTransaction table contains a record where TransactionId is equal to the alue in the variable @transactionid.
    1. If yes, you do the "(Omitted)" code
  3. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜