开发者

Adding table lock manually to specified table in SQL Server

开发者 https://www.devze.com 2023-01-05 05:02 出处:网络
I want to INSERT into one tables but prevent INSERTING to 开发者_如何学编程another one. It is possible to LOCK for example table a for INSERTING, INSERT to table b and then UNLOCK table a?

I want to INSERT into one tables but prevent INSERTING to 开发者_如何学编程another one. It is possible to LOCK for example table a for INSERTING, INSERT to table b and then UNLOCK table a?

TABLOCK can lock only the table I am INSERTING in.

Thanks

Martin Pilch


SQL Server does not allow locking objects like you would do semaphors. Also, locking a table will not make it read-only; it will make it locked out for everybody.

You can place a lock by using a table hint such as SELECT * FROM MyTable WITH (LOCKNAME) but that is not a good programming practice.

0

精彩评论

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