lock a table in sql server 2008 after select

耗尽温柔 提交于 2019-12-11 18:06:32

问题


I have a main currency table. Which has two fields, one currency Type and currency value. User can not be changed once a user start working with the DB. I need to lock my Currency table through SQL Server 2008 Query once user select one value. Can any one help me or suggest me for DB LOCK query.


回答1:


You can use NOLOCK for your objects.

For example :

SELECT TOP 10 * FROM Orders WITH(NOLOCK) where UserName = 'VadaVici'



回答2:


We had the same problem on a table in our database. Found this and it worked for us:

SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
BEGIN TRANSACTION;
SELECT * FROM dbo.MyTable WITH (TABLOCKX);

The table will be locked until a COMMIT TRANSACTION or ROLLBACK TRANSACTION is executed.

Hope it helps somebody in the future...



来源:https://stackoverflow.com/questions/15333886/lock-a-table-in-sql-server-2008-after-select

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!