Hyphens in column names in MySQL DB

前端 未结 6 557
無奈伤痛
無奈伤痛 2020-11-27 08:06

May be this question has been answered before but I couldn\'t find it.

I am using a 2/3 yr old MySQL database which has hyphens in its column names. When I try to us

6条回答
  •  猫巷女王i
    2020-11-27 08:18

    It's better to not use hyphens in your column names. I suffered a big problem with JOIN statements where hyphens caused big trouble - there even escaping names in back ticks didn't work.

    Convert the column names to use underscores - this is the safest way to go.

    As an alternative - in case where even backticks should cause problems (you know it happend to me) and you want to stick to hypens no matter what - just create a VIEW to reflect the same table with all the fields and query the view instead of the original table.

提交回复
热议问题