1

Scenario I have a MYSQL table with a column called text. I've only recently realized that TEXT is in fact a MYSQL keyword, but I haven't had any problems using that column name.

Background I've already noticed from the MYSQL documentation that there is a difference between reserved words and keywords: reserved words are more restrictive in that they need to be quoted with back ticks if you want to use them as identifiers. This question is about keywords, not reserved words.

Question Are there any problems that could come up with having a keyword such as text or type as a column name?

  • If yes, in which scenario?
  • If not, why do we even care that they are keywords? Is there any difference at all to a custom name?
E. Villiger
  • 876
  • 10
  • 27
  • As far as I know there are no *real risks* to this since you can escape the col names in for example `. I do think you should name those colums different cause queries get really messed up by having reserved words as col names – Tomm May 12 '18 at 07:12
  • 2
    @Tomm The question is about _non_ reserved MySQL keywords which _don't_ require escaping. – Tim Biegeleisen May 12 '18 at 07:18
  • 1
    I could find nothing towards an answer elsewhere. My best explanation is that the reserved keywords are critically important to the parsing of a query. By making them reserved, MySQL's parser does not have to "think" about what `SELECT` means. This makes the logic of the parser much simpler than if, upon seeing every `SELECT`, for example, it would have to backtrack many times to consider all possibilities. – Tim Biegeleisen May 12 '18 at 07:27
  • That sounds reasonable, thank you. (On a side note: `SELECT` is actually a reserved word; your answer was probably meant for a keyword such as `TEXT`) – E. Villiger May 12 '18 at 07:32
  • 2
    Personally, I think the most likely issue is the potential it has to confuse folks who get to support your code. – Paul Maxwell May 12 '18 at 07:37
  • Personally I prefer words that are less likely to cause confusion - student_type, student_text, that kind of thing. – Strawberry May 12 '18 at 08:47

0 Answers0