0

I need to block a table from being accessed by any other process unless my current operation(usually a INSERT or an UPDATE) is completed, Is there a way to lock and unlock sql server tables from .net code without using stored procedures, i need these to avoid business rules based duplicate records from being entered into the table.

4

2 回答 2

1

更好的是,不要锁定表(尤其是如果更新/插入数据需要很长时间),而是仅在所有数据都更新/插入后提交更改。

于 2012-07-13T12:22:21.053 回答
0

你用一个提示

插入带有(tablock)(colx)值('newValuex')的表中;

如果 valuex 是主键或具有唯一约束,那么它将被强制执行。

但是您不需要 tabloc 来强制执行该约束。

如果您有多个语句,那么您可以将它们包装在一个事务中。

于 2012-07-13T13:08:56.760 回答