SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict agentforte's Avatar
    Join Date
    May 2007
    Location
    Toronto, ON, Canada
    Posts
    213
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question should columns always be quoted in MySQL queries?

    Is there any benefit to `quoting` columns in mysql queries if they do not interfere with the query?

    Does this affect performance?

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,347
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    you mean backticking, not quoting, right?

    no, you should never do it

    the only time it's necessary is if the column or table name either contains special characters (like a space) or is a reserved word -- and you should never, ever assign a name like that

    there is no benefit to backticking, and there is a serious drawback (loss of legibility)

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Addict agentforte's Avatar
    Join Date
    May 2007
    Location
    Toronto, ON, Canada
    Posts
    213
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Rudy.

    I did mean backticking. I use constants to define my database tables and columns in a "define_db" file. This makes it easy if I ever want to change column names to be more descriptive or follow a better format. So I guess it should be easy to change any column names that are reserved words.

    I have a "from" and "to" column to display content "from" date1 "to" date 2 and I liked the idea of just using "from" as a column name. Not any more though!

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,875
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    date_from is probably a reasonable name for the field, providing more info about what the date is for in the name would be even better.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •