What rules apply to naming a mysql column?

István Pálinkás picture István Pálinkás · Aug 24, 2014 · Viewed 11.1k times · Source

In a MySQL table, naming a column, can I use

  • spaces
  • uppercase letters
  • UTF8 characters

What other rules shall I follow?

( MySQL5 )

Answer

brian picture brian · Aug 24, 2014

Yes, Yes, and Yes.

I like underscores between field names and no uppercase, but I don't want to start a flame war.

Another good reason to not use special characters in column names is you, or others are eventually going to have to type that over and over in your application. I'd stick to the standard english alphabet.

Good column names:

account_id
user_id
first_name

Bad column name:

Ȩ̬̩̾͛ͪ̈́̀́͘ ̶̧̨̱̹̭̯ͧ̾ͬC̷̙̲̝͖ͭ̏ͥͮ͟Oͮ͏̮̪̝͍M̲̖͊̒ͪͩͬ̚̚͜Ȇ̴̟̟͙̞ͩ͌͝
uraniumType☢☢☢☢