Alex Rivera | Logout

When having an identity column is not a good idea?

Asked 2009-05-31T21:36:44.667
9

In tables where you need only 1 column as the key, and values in that column can be integers, when you shouldn't use an identity field?

To the contrary, in the same table and column, when would you generate manually its values and you wouldn't use an autogenerated value for each record?

I guess that it would be the case when there are lots of inserts and deletes to the table. Am I right? What other situations could be?

Edit
Report

1 Answer

0

If I need a surrogate, I would either use an IDENTITY column or a GUID column depending on the need for global uniqueness.

If there is a natural primary key, or the primary key is defined as a unique combination of other foreign keys, then I typically do not have an IDENTITY, nor do I use it as the primary key.

There is an exception, which is snapshot configuration tables which I am tracking with an audit trigger. In this case, there is usually a logical "primary key" (usually date of the snapshot and natural key of the row - like a cost center or gl account number for which the row is a configuration record), but instead of using the natural "primary key" as the primary key, I add an IDENTITY and make that the primary key and make a unique index or constraint on the date and natural key. Although theoretically the date and natural key shouldn't change, in these tables, if a user does that instead of adding a new row and deleting the old row, I want the audit (which reflects a change to a row identified by its primary key) to really reflect a change in the row - not the disappearance of a key and the appearance of a new one.

answered 2009-06-01T00:34:24.700

Your Answer