简体   繁体   中英

SQL Server 2000 stored procedure get unique number from unique ID row avoiding concurrent request issues

Using a central SQL Server 2000 database I have a table called UNIQUE_ID_COUNTER . Using the following table structure this holds several rows maintaining the unique ID's assigned to different types of object forwarded to a further system.

UNIQUE_ID INT,
NAME VARCHAR(MAX)

234, "APPLES"
189, "PEARS"
...

Each time the stored procedure is called from a client the UNIQUE_ID is selected via NAME and then incremented by 1.

As we have many high request clients in some fringe cases where multiple clients make this request at the same time we are getting multiple UNIQUE_ID 's with the same number.

How can I avoid this but still ensure the stored procedure returns the correct value and increments the UNIQUE_ID column?

Your help would be most appreciated! :)

The preferred and recommend solution is pretty simple: let the database handle all those pesky detail by using a INT IDENTITY column.

Then you'll never have duplicates, you don't need to worry about incrementing your counter - everything's handled for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM