Auto Generated Key

An auto-generated key is a key for a RelationalDatabase table that rather than reflecting some element or attribute from the problem domain or the data/relationships to be stored in the database; is generated automatically somehow--and doesn't have any meaning, other than being a unique MagicCookie? which can unequivocally identify a particular record within a database.

Sometimes, this is done because a particular record will be in one-to-one correspondence with a particular external entity, and said external entity has no particular attribute which is unique. A customer ID number is one example; there is no globally accepted unique ID for persons that can be used. Social security numbers come close in the US; though many object to their use for this purpose. Names cannot be, in general, used for this purpose--lots of folks around with the same name. (But don't tell that to the ScreenActorsGuild?, the union representing waiter^H^H^H^H^H^Hactors in Hollywood. The SAG requires that actors' screen names be unique; were a fresh young actor whose name were "Brad Pitt" to seek work in Hollywood; he would have to find a different nom de cinema to use, as "Brad Pitt" is already taken. "Bradley Pitt", "Brad Q. Pitt", or any unused pseudonym would be acceptable.)

Other times, AutoGeneratedKey's to give a particular record an ObjectIdentity, even when said record isn't in one-to-one correspondence with any particular real-world entity. When a new record-cum-object is created, it is assigned a new AutoGeneratedKey. As the record-cum-object is mutated, the other attributes of the key may change, but the auto-gen key stays the same. When the record-cum-object is deleted from the database, the key is thrown away. (Sometimes, such keys are recycled; but that is often considered a bad idea).

AutoGeneratedKeys are, depending on your point of view, either a beneficial feature for database products or an ugly hack, allowing one to simulate non-relational data models in a RelationalDatabase.


See also: AutoKeysVersusDomainKeys [editor: merge in order?]


CategoryRelationalDatabase


EditText of this page (last edited October 15, 2004) or FindPage with title or text search