Hyphens in column names in MySQL DB

euphoria83 picture euphoria83 · May 20, 2009 · Viewed 29.9k times · Source

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 use these names from my Java code, the names are broken at the hyphen (e.g. air_port becomes air) and thus are not found. I tried replacing hyphens to underscores in my code hoping that the DB might treat them equally but that doesn't work.

How can I escape the hyphen or how can I access these columns ? Could this be an issue of the character set being used ?

Answer

dar7yl picture dar7yl · May 20, 2009

enclose the names within `back-ticks`