简体   繁体   English

SQL Server 2000存储过程从唯一ID行获取唯一编号,从而避免了并发请求问题

[英]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 . 使用中央SQL Server 2000数据库,我有一个名为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. 使用以下表结构,该表将保留几行,以维护分配给转发给另一系统的不同类型对象的唯一ID。

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. 每次从客户端调用存储过程时, UNIQUE_ID通过NAME选择UNIQUE_ID ,然后将其递增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. 由于在某些情况下有许多高要求的客户,在这种情况下,有多个客户同时发出此请求,因此我们得到了多个具有相同编号的UNIQUE_ID

How can I avoid this but still ensure the stored procedure returns the correct value and increments the UNIQUE_ID column? 如何避免这种情况,但仍要确保存储过程返回正确的值并递增UNIQUE_ID列?

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. 首选的推荐解决方案非常简单:通过使用INT IDENTITY列,让数据库处理所有那些令人讨厌的细节。

Then you'll never have duplicates, you don't need to worry about incrementing your counter - everything's handled for you. 这样一来,您将永远不会有重复的商品,也不必担心增加计数器的数量-一切都由您完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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