ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hello All,
Basically I am trying to implement assigning of unique consecutive integers from a particular row in a table in MSSQL 2000.
Example pseudocode:
<code>
SET ISOLATION LEVEL REPEATABLE READ
SELECT @VAR1 = NextAvailableNumberColumn FROM TheTable WHERE pk=@pk
UPDATE TheTable SET NextAvailableNumberColumn = @VAR1 + 1 WHERE pk=@pk
RETURN @VAR1
COMMIT
</code>
Will this ensure that each client will always get a unique number, or is it possible that this could return the same number to more than one client? Also, if this works, could someone please explain why. It seems to me that if the tranaction was ran concurrently with two instances, then the first select would issue a shared lock for both transactions, and when the update was issued there would be deadlock because the row would be share locked by the two transactions. Please advise.
Thanks for the reply Crito. If I understood correctly, the method you showed is for generating the next consecutive number on an insert. I am sorry if I did not make myself clear in my post. The WHERE clause in the update statement shows that I must keep an "autonumber" for each row in the table. Basically, each row in the table defines a particular range within which consecutive numbers must be generated in. For example: Row 1 = Company A, PO Number Range 1-1000, NextAvailablePONum = 10, Row 2 = Company B, PO Number Range 1001-2000, NextAvailablePONum = 1001. Then when the client generates a PO number for a particular company, this stored procedure gets called, and gets the next available po number from the row, then increments the column value for that row by one. The reason it was not implemented with identity columns is that there are a couple of hundred companies.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.