Editorials

Collaboration is the Best Primary Key

I had a lot of input from many of you regarding naming conventions for the primary key of a table. One thing that was common in all of the replies, either written explicitly, or implicitly, was that consistency matters. If you have a convention, regardless of what it is, and always use it in all of your databases, it is a lot easier to work with them.

It was clear that coders should be able to work with any convention. If you put the table name in the key column, or do not use aliases in place of the table name, then the key being used will always be clear when doing a filter or a join.

One reader brought up a great point about the value of composite keys, where the naming convention has a direct impact. However, even those proposing the use of Id as the primary key in a table, also included the table name prefix when using the key as a foreign key in another table. Generally, any table with a composite key will define the keybased on two or more foreign keys, so the table names will be prefixed anyway.

I’m not seeing any one compelling reason to go any particular direction. It seems like the best advice is to collaborate with your co-workers…figure out an implementation to get along. Then be consistent.

Cheers,

Ben