SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Sep 2005
    Posts
    159
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Commas and so on in Field names - a good idea?

    I've had a bit of a disagreement with a couple of colleagues who think it's fine to put commas and other characters in the names of database fields. I'm emphatic in my dislike of the idea, but colleagues think it's fine. Who is right?

    I hasten to add that none of the three of us are database specialists, but I've spoken to a couple of SQL specialists who agree with me that it's not a good idea.

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    The comma in SQL is used to separate column names, so putting it IN the column name is a horrible idea. It's just going to lead to errors and messy troubleshooting in the future, and every single query that's written has to enclose the column names by whatever the escape character is in your RDBMS (backticks in some, square brackets in some, etc)... which also makes the SQL less portable to a different RDBMS should the company change in the future.

  3. #3
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,653
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    What Dan said. Field names should be as bog standard 7 bit ascii with no spaces as possible, you never know what some library will barf on.

  4. #4
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,868
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Stick to letters, numbers, and underscores and avoid reserved words - include anything else and your code is going to only work on the one database and will require a major reqrite if you ever need to shift it to a different one. Also including other characters introduces more scope for errors in the code and so will add signficantly to testing time.
    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
  •