pf » Naming Tables
Naming Tables
I am working on a project that has a database table called people. Now I am pretty sure that I was the one to name this table so I will take the blame, but it has been kind of hard to work with that name.
Here's why:
- For some reason I have trouble typing
peoplequickly, it tends to be a typo. This is either just me, or due to where the letters are on they keyboard. - It doesn't make sense to have a singleton called
peopleso you end up naming itperson, this can lead to some confusing naming.
My preference is to use plural words for table names, because you usually have multiple rows in the table, and it reads better in SQL.
There are some cases though, like this one where the plural words can cause a muck. Whare are your naming conventions, and why?
I've since changed my thinking to something very close to Peter's approach. If you keep everything singular, you never have to really think about it. It also supports my cfc code generator better since a bean seems awkwardly named if it's plural.
If you had a cfc named "users.cfc", I would expect to see collections returned instead of a single user.
Also, precursor conventions are nice as well, especially when you have collections of similar data. At my job, we have a CMN_xxxxx set of tables for collecting common data from our clients, and then a set of YYY_xxxxx set of tables for the particular extra information that each client requires us to store. That helps keep table groupings in order as well.
In User table, identity is UserID. If user has a company FK, it is CompanyID (again assuming "ID" FKs).
I personally don't love hungarian style notation (putting data type into name) as it makes refactoring harder as it is not unusual to have to refactor data types. I REALLY dislike hungarian in coe as it makes refactoring a lot more work, but I guess it isn't as bad in tables as long as you alias everything in your DAOs. I get the benefits, but I'm more than happy to use design view (or metadata or runtime reflection) to get the data type as a separate bit of data. Just my preference.
I also try to avoid prefacing column names with the "object" name as a convention so it is FirstName, not UserFirstName. Only exception that comes up is Username which has a fundamental meaning.
I've played with package naming of tables like Greg and am mixed. I like putting commerce and cms tables close to each other but can't decide if it is good or bad as a rule.
http://livedocs.macromedia.com/wtg/public/coding_standards/database.html
I agree 100% with each item. Only one comment, though, WHY IS IT THAT ALL DBAs THINK THEY HAVE TO SHOUT?!
I know they aren't as cool as programmers, but shouting at us all the time won't fix that :->
Until Rails I did not like plural names for tables but now its the only thing that makes the sense. I also like prefixing all tables with a short code, to indicate what groups the tables together. (ex. the user table for my blog would be BLOG_USERS).
But where that really gets helpful though is in the naming of the columns. Our columns are the two character prefix, the three character table name, and then you have five characters to actually name the field. So our username field in the users table is pjusruser. What makes this nice is if you are using a field, you automatically know what table it came from, and it makes joins much much easier. It seems like a lot of typing at first, but when all of your tables are 9 characters long and all of your columns are a max of 10 characters long, it really makes your sql a LOT easier to read and maintain.
This was mainly done for the rpg work done on the 400, but it lends itself well to web development too.
- Mastering CFQUERYPARAM
- Google Code Search for ColdFusion
- Speaking at CFUNITED 2008
- Getting ColdFusion SQL Statements from SQL Server Trace
- CFSCRIPT Cheatsheet
- 3 New Image Effects for ColdFusion 8
- Googlebot to Submit Web Forms
- ColdFusion 8 Update 1 Fixes some Image Processing Quirks
RSS
add to del.icio.us
Pete Freitag is a software engineer, and web developer located in











