问题
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