Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any good reasons that I should not use - (dash) in field names in MySQL?

Tags:

mysql

I have field name category_id in product table.

And also I want name field of category id as category-id.

Is there any good reasons that I should not use - in a field name?

Where can I find which character I should not use in MySQL field and table name?

like image 356
shin Avatar asked Jan 05 '10 20:01

shin


3 Answers

The major reason against use of hyphen is that most references must then quote the field names. Otherwise they will look like a subtraction operator, both to MySQL and humans.

like image 102
wallyk Avatar answered Nov 13 '22 21:11

wallyk


You can take a look at the reserved words list

Generally, you can use whatever name you wish as long as you wrap it in backquotes.

like image 25
Matteo Riva Avatar answered Nov 13 '22 22:11

Matteo Riva


Safest bet is to stick with alphanumerics + _. Thats pretty standard in terms of "safe" naming, as none of those characters can be misrepresented as operator symbols.

like image 36
cyberconte Avatar answered Nov 13 '22 23:11

cyberconte