Expert Answer Center > Experts On Demand > View Answer
EMAIL THIS
Experts on Demand
  EXPERTS ON DEMAND HOME     POSE A QUESTION     VIEW ANSWERS     BROWSE BY TOPIC        RSS FEEDS  
We have drawn up some company standards for the naming of tables and columns. However, there has been some disagreement on one point -- the naming of the columns. Each table has a three-letter acronym that is the table alias, and there are two camps on the naming of the columns. One camp suggests that we prefix each column with the TLA, and the other camp believe this is not necessary. What would you recommend and why? QUESTION POSED ON: 27 JUL 2005
QUESTION ANSWERED BY: Rudy Limeback Excellent question. I'm firmly in the "no table prefix in column names" camp, with one exception: The only column that should have any type of table prefix in the column name is a foreign key.

When I create a table, I will often (but not always!) use a surrogate key, an auto_increment or identity column as the primary key. I always give this column the name ID. Then, when it's time to reference this primary key in a foreign key somewhere, you cannot call the foreign key ID, too, because that would clash with the primary key ID in that table. Therefore all foreign keys are called Entity_ID, where "Entity" is formed from the table name of the table it's referencing. This allows you to have a table containing several foreign keys, each named differently, each identifying the table it's referencing. So you can have a SalesTransaction table, with an ID primary key and foreign keys Cust_ID (referencing the Customers table ID key), Prod_ID (referencing the Products table ID key), and so on.

Other than that, no other columns should have a prefix as part of the column name to identify the table. This means that a lot of tables have columns like NAME, STATUS, DATE_UPDATED and so on.

This also means that you would never use a NATURAL JOIN because it would join on the wrong columns. But with a prefix scheme, you wouldn't use a NATURAL JOIN either, because it would join on no columns.

Without a prefix scheme, you need to be careful when writing a join; be sure to qualify each column using either the table name or a table alias. But this is self-documenting, and, on balance, qualifying column names used in a join by their table name or table alias is a good thing. Besides, even with a prefix scheme, you will still have to qualify some columns -- the foreign keys!

HomeExperts on DemandIT Expert Webcast SeriesExpert KnowledgebaseSite Index
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts