Using backticks around field names

前端 未结 11 1303
-上瘾入骨i
-上瘾入骨i 2020-11-22 02:05

After reading a couple of answers and comments on some SQL questions here, and also hearing that a friend of mine works at a place which has a policy which bans them, I\'m w

11条回答
  •  礼貌的吻别
    2020-11-22 02:25

    Using backticks permits you to use alternative characters. In query writing it's not such a problem, but if one assumes you can just use backticks, I would assume it lets you get away with ridiculous stuff like

    SELECT `id`, `my name`, `another field` , `field,with,comma` 
    

    Which does of course generate badly named tables.

    If you're just being concise I don't see a problem with it, you'll note if you run your query as such

    EXPLAIN EXTENDED Select foo,bar,baz 
    

    The generated warning that comes back will have back-ticks and fully qualified table names. So if you're using query generation features and automated re-writing of queries, backticks would make anything parsing your code less confused.

    I think however, instead of mandating whether or not you can use backticks, they should have a standard for names. It solves more 'real' problems.

提交回复
热议问题