Skip to content Skip to sidebar Skip to footer

Lock A Table In Sql Server 2008 After Select

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

Solution 1:

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...

Solution 2:

You can use NOLOCK for your objects.

For example :

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

Post a Comment for "Lock A Table In Sql Server 2008 After Select"