The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

uid

What's a good column name for the primary key of a table?

I usually call it 'uid' whatever the table is. Some people use the name of the table (e.g. customerID).

What do you do and why?
Colm O'Connor Send private email
Thursday, April 14, 2005
 
 
For the table named Customers, I prefer CustomerNo. CustomerID is also good. If every primary key is "uid" then you can make lots of subtle mistakes in complicated joins that will take more time to fix than they should.

If you have more than a few tables, keeping track of all the PKs with the same name will be cumbersome.

Where I am currently working, the prefered would be CustomerID. I've seen some designs where "cid" would be the pk for a customer table. OK. So you have a customer table with a pk of cid, and a class table with a pk of cid, and you have a customer_classes table, with 2 columns both named cid? Which cid is the cid you are looking for? Are these the droids you are looking for? No? Ok, move along then... :)
Peter
Thursday, April 14, 2005
 
 
I also typically use unique names for index columns. If you're doing anything beyond a simple join, unique names just make life easier.
Joseph LeBlanc Send private email
Thursday, April 14, 2005
 
 
"For the table named Customers, I prefer CustomerNo. CustomerID is also good. If every primary key is "uid" then you can make lots of subtle mistakes in complicated joins that will take more time to fix than they should."

Personally I'd say you would want to use a table prefix when doing any complex join's that way there is no ambiguity.

But I would agree a proper name would be better than simply uid, it make more sense that way if you display the value on reports forms etc.
gilf Send private email
Friday, April 15, 2005
 
 
I use a table prefix on most joins and I get Visual Studio to autogenerate nearly all of them anyway.

I suppose there is the argument that you don't need to use a  table prefix to disambiguate the column if you name all primary key columns differently.

Do many people use the uid on forms/reports? Typically the only place I'd have it visible to the user is in URIs.
Colm O'Connor Send private email
Friday, April 15, 2005
 
 
Suthern Send private email
Tuesday, April 19, 2005
 
 
If, like me, you have the misfortune to work with Access, you'll quickly regret using the same name for PKs -- when creating a query Access seems to assume that because the fields have the same name they must be related, and adds a bunch of joins for you.  Bastard thing!
Mat Hall Send private email
Tuesday, April 26, 2005
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
 
Powered by FogBugz