0

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.

San20130121
  • 11
  • 2
  • 6

2 Answers2

3

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

Community
  • 1
  • 1
Reynier Booysen
  • 281
  • 2
  • 14
0

You can use NOLOCK for your objects.

For example :

SELECT TOP 10 * FROM Orders WITH(NOLOCK) where UserName = 'VadaVici'
Vishal Suthar
  • 17,013
  • 3
  • 59
  • 105
Hotkey
  • 103
  • 7
  • Either I've misunderstood the question or OP misunderstood this solution but using `NOLOCK` in a select by no means prevents other users from changing the table. – Lieven Keersmaekers Mar 11 '13 at 08:45