Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Table Locking

Author  Topic 

cwburke
Starting Member

16 Posts

Posted - 2002-04-09 : 14:24:05
I have an application that will be used by multiple users. This application will create a new barcode number for each unit that is processed. I use the following code to generate the next barcode number. The objective here is to not allow two or more users simultaneous access to the table at the same time, thus eliminating the possibility of duplicate barcodes. Is the following statement the most effecient way to lock the table, generate the new barcode, update the table, then return the new barcode to the calling app:


Begin Tran
Select @Barcode=barcode+1
From tbl_pwe_svc_fsc_ref_barcode
With (TabLock, HoldLock)

Update tbl_pwe_svc_fsc_ref_barcode
Set barcode = @Barcode

Select barcode
From tbl_pwe_svc_fsc_ref_barcode
Commit tran



Thanks for your help,

Chris

AjarnMark
SQL Slashing Gunting Master

3246 Posts

Posted - 2002-04-09 : 18:54:56
Duplicate Post. See [url]http://www.sqlteam.com/Forums/topic.asp?TOPIC_ID=14747[/url] for answers.

Lock please.

------------------------
GENERAL-ly speaking...
Go to Top of Page
   

- Advertisement -