SQL Best Practices – Why Prefixing Column Names Is Bad

sql

According to a popular SO post is it considered a bad practice to prefix table names. At my company every column is prefixed by a table name. This is difficult for me to read. I'm not sure the reason, but this naming is actually the company standard. I can't stand the naming convention, but I have no documentation to back up my reasoning.

All I know is that reading AdventureWorks is much simpler. In this our company DB you will see a table, Person and it might have column name:

Person_First_Name
or maybe even
Person_Person_First_Name (don't ask me why you see person 2x)

Why is it considered a bad practice to pre-fix column names? Are underscores considered evil in SQL as well?


Note: I own Pro SQL Server 2008 – Relation Database design and implementation. References to that book are welcome.

Best Answer

Underscores are not evil just harder to type. What is bad is changing standards midstream without fixing all the existing objects. Now you have personId, Person_id, etc. and can't remember which table uses the underscores or not. Consistency in naming (even if you personally don't like the names) helps make it easier to code.

Personally the only place I feel the need to use the tablename in a column is on the ID column (the use of just ID is an antipattern in database design as anyone who has done extensive reporting queries can tell you. It's so much fun to rename 12 columns in your query every time you write a report.) That also makes it easier to immediately know the FKs in other tables as they have the same name.

However, in a mature database, it is more work than it is worth to change an existing standard. Just accept that is the standard and move on, there are far more critical things that need to be fixed first.