Using backticks around field names

前端 未结 11 1323
-上瘾入骨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:44

    If you ask to me, backticks should always be used. But there are some reasons why a team may prefer not to use them.

    Advantages:

    • Using them, there are no reserved words or forbidden chars.
    • In some cases, you get more descriptive error messages.
    • If you avoid bad practices you don't care, but... in real word, sometimes they are a decent way to avoid SQL injections.

    Disadvantages:

    • They are not standard and usually not portable. However, as long as you don't use a backtick as part of an identifier (which is the worst practice I am able to imagine), you can port your query by automatically removing backticks.
    • If some of your query come from Access, they may quote table names with " (and maybe you can't remove all the " blindly). However, mixtures of backticks and double quotes are allowed.
    • Some stupid software or function filters your queries, and has problems with backticks. However, they are part of ASCII so this means that your software/function is very bad.

提交回复
热议问题