Do underscores in table names affect performance or cause issues on some platforms?
For example, user_profiles
Would it be better to use user
I found a few links to MySQL bugs that have either been marked closed or can't reproduce regarding underscores. As far as I know there are no issues - I always use underscores over camel-case and haven't experienced any problems.
You should avoid it. Although it is a permitted character in MySQL documentation, it appears it might cause trouble. For example, in MySQL 5.0 & 5.1 (and may be later versions), the query cache is never hit for queries involving a table name containing an underscore.
Nope. Underscores are perfectly legal in table names.
This page here in the MySQL documentation tells you about what characters are allowed.
Basically:
Permitted characters in unquoted identifiers:
ASCII: [0-9,a-z,A-Z$_]
Extended: U+0080 .. U+FFFFPermitted characters in quoted identifiers:
ASCII: U+0001 .. U+007F
Extended: U+0080 .. U+FFFF
Personally I tend to stick with lowercase a-z, the occasional number, and underscores. But as @Vince said, it's just personal preference.
Many database visualization tools such as SQuirreL SQL and DbVisualizer also treat the underscore as a wildcard of sorts, grouping tables "matching" into a tree. For example, a table "document_a" and related tables "document_a_details", "document_a_history". In DbVisualizer, looking at the "document_a" table shows columns for all three tables.
This is generally not a problem, but can be confusing. For example, using SQuirreL SQL's graphing tools to generate ERDs combines columns from multiple tables into a single table and draws connectors for the relationships of all of these columns in the ERD. This results in relationships being drawn that don't actually exist.
For this reason, I would not include underscores in table names.
The only issue I've seen is that when using mysqlshow to view the structure of a table it appears to treat the underscore as a wildcard and returns only matching table names if there is an underscore in the name.
I could find no way to view the table structure of a table if there is an underscore in the name. I just discovered and confirmed this myself this morning.
I know this to be true of MySQL versions 4.0.18 and 4.1.22 for older versions and 5.1.52 for newer. Perhaps this is documented somewhere (I haven't taken the time to look yet), but it might be a perplexing thing for others, so I decided to mention it when I ran across this question when looking for information on the problem myself.
I never had issues with underscore when naming my tables. It's just personal preference.