0

sql事务是否锁定事务中更新的表?

例如;

几个程序想要访问一个保存计数器值的 Foo 表。我想更改交易中的计数器值,如果它是反式的。在后续步骤中失败,则事务回滚并且计数器值保持不变(旧值)。在事务过程中,其他程序是否可以访问 Foo 表?

我正在使用 SQL Server 2008 RC

4

1 回答 1

1

On the subject of maintaining counters I would recommend you investigate 'Autoincrement' because this solves the problem you are addressing.

The limitation is that you cannot guarantee there are no gaps in the sequence. This is because of the answer to your second question.

If transaction 'A' begins with a new counter value, Tran 'B' can follow with another before 'A' has committed - so yes - the table is accessible.

If you try and manage counters yourself (perhaps to try and avoid gaps) you will have to cope with the possibility that tran 'C' comes along after 'A' has rolled back but before 'B' has committed - and you will have a duplicate. Using the AutoIncrement mechanism will guard against that, but the counter will have a gap left by Tran 'A'.

Hopefully that is the issue you are tackling.

于 2013-09-11T08:38:38.930 回答