Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 896995
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:49:07+00:00 2026-05-15T14:49:07+00:00

SQL seems to be the most neglected language when it comes to formatting nicely

  • 0

SQL seems to be the most neglected language when it comes to formatting nicely and readably… And as SQL statements can be incredibly detailed and complex, it makes it extremely hard to work with. But I find that when I try to format my SQL code in the best way possible I’m sometimes unsure of how to do it. I know the standards for Java, C#, Python, etc…. but when it comes to SQL I haven’t seen too many guidelines or accepted practices. What are tips/rules for formatting SQL so that it’s clear, legible, and logical? Can you give example code to illustrate? What have you found to be the most standard, accepted way of formatting SQL?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T14:49:07+00:00Added an answer on May 15, 2026 at 2:49 pm

    You could try checking out Joe Celko’s book SQL Programming Style. I’m sure that there are a lot of people who disagree with his style, but it’s a good start.

    Some of my own “rules”

    • SQL keywords are always all upper-case
    • Table names are “proper” case, while columns and variables are all lower-case
    • Each “major” clause in a statement is at the start of a line
    • JOIN and WHERE criteria appear beneath and are indented and aligned
    • Nested items are indented further
    • I use aliases for all tables and views

    For example:

    SELECT
        column_1,
        column_2,
        CASE
            WHEN column_5 = 'Blah' THEN 1
            WHEN column_6 = 'Blah' THEN 2
            ELSE 3
        END AS column_alias
    FROM
        My_Table MT
    INNER JOIN My_Other_Table MOT ON
        MOT.column_1 = MT.column_1
    WHERE
        MT.column_2 = 'Some Value' AND
        (
            MT.column_3 = 'Some other value' OR
            MT.column_4 = 'Some other value'
        )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

From what I've been testing it seems that you can only use standard SQL
There seems to be some hysteria about SQL Injection attacks. Most recently, here How
LuaSQL , which seems to be the canonical library for most SQL database systems
I am doing some performance testing and have found that SQL seems to be
I'm pretty familiar with grails however my sql logging seems to always be on
This seems weird: [SQL FIDDLE] The two users are definitely different i.e 1<>2. So
It seems that SQL Server has a fair amount of XML support. Mostly I've
It seems that SQL Server does not accept numbers formatted using any particular locale.
This evaluation in sql doesn't seems to work properly for some reason but i
I am using SQL Server 2008 Web Edition and it seems my SQL queries

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.