How to create unique user key
Posted
by Grayson Mitchell
on Stack Overflow
See other posts from Stack Overflow
or by Grayson Mitchell
Published on 2010-05-12T21:50:03Z
Indexed on
2010/05/12
21:54 UTC
Read the original article
Hit count: 188
database
|sql-server
Scenario: I have a fairly generic table (Data), that has an identity column. The data in this table is grouped (lets say by city).
The users need an identifier in order for printing on paper forms, etc. The users can only access their cites data, so if they use the identity column for this purpose they will see odd numbers (e.g. a 'New York' user might see 1,37,2028... as the listed keys.
Idealy they would see 1,2,3... (or something similar)
The problem of course is concurrency, this being a web application you can't just have something like: UserId = Select Count(*)+1 from Data Where City='New York'
Has anyone come up with any cunning ways around this problem?
© Stack Overflow or respective owner