What is the best way to design a table with an arbitrary id?
Posted
by
P.Brian.Mackey
on Programmers
See other posts from Programmers
or by P.Brian.Mackey
Published on 2011-11-22T14:36:31Z
Indexed on
2011/11/23
10:09 UTC
Read the original article
Hit count: 359
database-design
|sql-2000
I have the need to create a table with a unique id as the PK. The ID is a surrogate key. Originally, I had a natural key, but requirement changes have undermined this idea. Then, I considered adding an auto incrementing identity. But, this presents problems.
A. I can't specify my own ID.
B. The ID's are difficult to reset.
Both of these together make it difficult to copy over this table with new data or move the table across domains, e.g. Dev to QA. I need to refer to these ID's from the front end, JavaScript...so they must not change.
So, the only way I am aware of to meet all these challenges is to make a GUID ID. This way, I can overwrite the ID's when I need to or I can generate a new one without concern for order (E.G. an int
based id would require I know the last inserted ID).
Is a GUID the best way to accomplish my goals? Considering that a GUID is a string and joining on a string is an expensive task, is there a better way?
© Programmers or respective owner