Wrox Programmer Forums
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 9th, 2004, 08:02 PM
Authorized User
 
Join Date: Jun 2003
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Default Table Locking

Anyone know the equiv M$ command that does table locking such as below? This code snippet is from Sybase and I need to convert it to M$ SQL2k - SP3.

/* Lock the tables that will be transferred TO DW.
* The locks will be removed when this stored procedure
* is exited. "mode wait" means wait patiently
* until the table can be locked. */

lock table CPLACT in exclusive mode wait
lock table CPLSUP in exclusive mode wait
lock table CNSACT in exclusive mode wait
lock table CNSSUP in exclusive mode wait

_________________________
Joe Horton
Database Developer / Software Engineer
WISHA/Legal Services Software Development
Department of Labor and Industries
Voice (360) 902-5928 fax (360) 902-6200
__________________
_________________________
Joe Horton
Database Developer / Software Engineer
WISHA/Legal Services Software Development
Department of Labor and Industries
Voice (360) 902-5928 fax (360) 902-6200
 
Old February 9th, 2004, 09:17 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

Explicit locking of rows in a table, or of the entire table, is handled via "locking hints" in SQL Server. These hints may be placed in SELECT, INSERT, UPDATE, and DELETE statements and are added to the table(s) in the FROM clause, as, e.g:
Code:
SELECT * FROM MyTable WITH (TABLOCKX, HOLDLOCK)
WHERE ...
will acquire an exclusive lock (read and update lock) on the table and hold it until the transaction in which it resides is completed (committed or rolled back). See "table hints" in the BOL index for the list of the various hint values.

Jeff Mason
Custom Apps, Inc.
www.custom-apps.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
DB table locking. madhukp Classic ASP Basics 5 June 26th, 2004 06:22 AM
Locking down a table lryckman Access 6 March 1st, 2004 08:50 AM
Access 97 Table locking problems timmaher Access VBA 1 November 5th, 2003 11:05 AM
Locking Peter Riley SQL Server ASP 3 June 5th, 2003 07:24 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.