SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Evangelist DMacedo's Avatar
    Join Date
    May 2004
    Braga, Portugal
    0 Post(s)
    0 Thread(s)

    Cool Database Naming Conventions & Standards

    So I've been trying to find a decent Naming Convention for MySQL as well as Standards for SQL queries (Use SELECT *? COUNT(`id`)? Type 'WHERE' and not 'where'? Use `backticks`? New lines where, exactly? How does that improve the SQL readability?!?), to finally place the best practices in writing and try to adhere to them!

    I've been finding several resources through search on best practices, but few define the "why", and even more are incomplete.

    So I'd like to invite you all to share your conventions, not only to help me in finally write mine in stone, but to have a thread dedicated to them!

    (Whenever possible, please explain your choice, as there's a reason for everything...)
    ~ Daniel Macedo

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Toronto, Canada
    63 Post(s)
    3 Thread(s)
    okay, i'll start the ball rolling...

    Naming Conventions
    • do not embed the type-of-thing into the name-of-thing -- if you're going to call it tbl_employee, then you have to call it col_empid, col_name, etc.
    • check out ISO 11179

    Standards for SQL Queries
    • learn when it is appropriate to use the dreaded, evil "select star" (there only are a very few cases) -- in particular, never use it together with GROUP BY
    • for the love of $deity, use line breaks and indentation when wrinting SQL!! | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    163 Post(s)
    4 Thread(s)
    No standard, but I always avoid using back-ticks, simply because they're not on my keyboard
    I just give my tables and fields names that are not reserved MySQL keywords.

  4. #4
    reads the ********* Crier silver trophybronze trophy longneck's Avatar
    Join Date
    Feb 2004
    Tampa, FL (US)
    1 Post(s)
    0 Thread(s)
    if i know i'll be working on something in an IDE that support SQL syntax highlighting, i will write in all lower case. but if my IDE doesn't do SQL highlighting or i'm embedding SQL in another language (i.e., php) i capitalize reserved works, but leave objects (tables, columns, etc.) in lower case.
    Check out our new Industry News forum!
    Keep up-to-date with the latest SP news in the Community Crier

    I edit the SitePoint Podcast


Posting Permissions

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