HELP please on LOCK TABLE statement in program

HELP please on LOCK TABLE statement in program

Post by Kay Erkman » Thu, 31 Jul 1997 04:00:00



KenParis schrieb:

Quote:> I'm supporting one of our users remotely and I have very little
> knowledge
> of SQLServer.  She has a series of sequentially run programs which run
> by
> themselves.  They do alot of updating, so I suggested that she put a
> 'LOCK
> TABLE tablename IN EXCLUSIVE MODE' into each program for each table
> being
> used.

> She said it compiled fine but when she runs she gets an error saying
> 'invalid syntax near lock'.

> Any ideas?

> Thanks

   For my opinion, LOCK table will not be supported by SQL Server. For
locking a table in exclusive mode use a select count(*) for this table
with optimizer hint (EXCLUSIVE LOCK).

Kay Erkmann

 
 
 

HELP please on LOCK TABLE statement in program

Post by Tibor Karasz » Thu, 31 Jul 1997 04:00:00


Kay,

You can lock a table. Example:
BEGIN TRAN
SELECT * FROM AUTHORS (TABLOCKX HOLDLOCK)
....
COMMIT TRAN

Search in BOL for "TABLOCK", and you find the avaliable optimizer hints.
Note that a pageloch can be escalated to a table lock. This is
configurable... Search for "lock escalation".
--

MCSE, MCSD, MCT, SQL Server MVP
Cornerstone Sweden AB



Quote:> KenParis schrieb:

> > I'm supporting one of our users remotely and I have very little
> > knowledge
> > of SQLServer.  She has a series of sequentially run programs which run
> > by
> > themselves.  They do alot of updating, so I suggested that she put a
> > 'LOCK
> > TABLE tablename IN EXCLUSIVE MODE' into each program for each table
> > being
> > used.

> > She said it compiled fine but when she runs she gets an error saying
> > 'invalid syntax near lock'.

> > Any ideas?

> > Thanks

>    For my opinion, LOCK table will not be supported by SQL Server. For
> locking a table in exclusive mode use a select count(*) for this table
> with optimizer hint (EXCLUSIVE LOCK).

> Kay Erkmann


 
 
 

1. HELP please on LOCK TABLE statement in program

Why did you suggest this? Just to be safe, or were you noticing specific
problems? If updating is being done, an exclusive lock is automatically
acquired, but there are some issues regarding how much data is locked at
one time.

LOCK TABLE is not a SQL Server command. I'm not sure what compiled, but it
wasn't the SQL statement itself.

Locking is a BIG subject, and involves a thorough understanding of
transactions. I suggest you/she find some good reading material to give you
a background, and then you can come back and ask specific questions.

Check out Microsoft's KB on locking
The SQL Server BOL
SQL Server 6.5 Unleashed by SAMS Publishing
SQL Server Professional Journal from Pinnacle Publishing
TechNet
--
Kalen Delaney
MCSE, SQL Server MCT, MVP
For SQL Server Technical Seminars: Check out www.sqlinc.com



2. Dblinks: security

3. How to lock the table, help please.

4. Report Summarries

5. Table still locking, please help.

6. altering table

7. PARADOX TABLES NOT LOCKING. PLEASE HELP

8. Intentionally splitting data in a table across files.

9. TABLE LOCK/UNLOCK, PLEASE HELP!!!

10. Please Help: table locking

11. a little help with an ALTER TABLE statement, please

12. COMBO BOX, PLEASE HELP, PLEASE HELP, PLEASE HELP!

13. Need help with Hailstone Sequence program please Help