views:

113

answers:

2

Is there a command/SQL query to lock a particular table in MS SQL Server to stop all related transactions using ODBC?

+1  A: 

Use the table hints, such as:

SELECT * FROM MyTable WITH (TABLOCK, HOLDLOCK)

See Table Hints in Books Online for more details.

_J_
The TABLOCK hint is used to request a shared lock. You will most likely want to use TABLOCKX in order to obtain an exclusive lock.
John Sansom
+2  A: 

Try taking a look at this:

http://www.mssqlcity.com/Articles/Adm/SQL70Locks.htm

seanxe