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 116855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:14:38+00:00 2026-05-11T03:14:38+00:00

In my last job, we worked on a very database-heavy application, and I developed

  • 0

In my last job, we worked on a very database-heavy application, and I developed some formatting standards so that we would all write SQL with a common layout. We also developed coding standards, but these are more platform-specific so I’ll not go into them here.

I’m interested to know what other people use for SQL formatting standards. Unlike most other coding environments, I haven’t found much of a consensus online for them.

To cover the main query types:

select     ST.ColumnName1,     JT.ColumnName2,     SJT.ColumnName3 from      SourceTable ST inner join JoinTable JT     on JT.SourceTableID = ST.SourceTableID inner join SecondJoinTable SJT     on ST.SourceTableID = SJT.SourceTableID     and JT.Column3 = SJT.Column4 where     ST.SourceTableID = X     and JT.ColumnName3 = Y 

There was some disagreement about line feeds after select, from and where. The intention on the select line is to allow other operators such as ‘top X’ without altering the layout. Following on from that, simply keeping a consistent line feed after the key query elements seemed to result in a good level of readability.

Dropping the linefeed after the from and where would be an understandable revision. However, in queries such as the update below, we see that the line feed after the where gives us good column alignment. Similarly, a linefeed after group by or order by keeps our column layouts clear and easy to read.

update     TargetTable set     ColumnName1 = @value,     ColumnName2 = @value2 where     Condition1 = @test 

Finally, an insert:

insert into TargetTable (     ColumnName1,     ColumnName2,     ColumnName3 ) values (     @value1,     @value2,     @value3 ) 

For the most part, these don’t deviate that far from the way MS SQL Server Managements Studio / query analyser write out SQL, however they do differ.

I look forward to seeing whether there is any consensus in the Stack Overflow community on this topic. I’m constantly amazed how many developers can follow standard formatting for other languages and suddenly go so random when hitting 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. 2026-05-11T03:14:39+00:00Added an answer on May 11, 2026 at 3:14 am

    I am of the opinion that so long as you can read the source code easily, the formatting is secondary. So long as this objective is achieved, there are a number of good layout styles that can be adopted.

    The only other aspect that is important to me is that whatever coding layout/style you choose to adopt in your shop, ensure that it is consistently used by all coders.

    Just for your reference, here is how I would present the example you provided, just my layout preference. Of particular note, the ON clause is on the same line as the join, only the primary join condition is listed in the join (i.e. the key match) and other conditions are moved to the where clause.

    select     ST.ColumnName1,     JT.ColumnName2,     SJT.ColumnName3 from      SourceTable ST inner join JoinTable JT on      JT.SourceTableID = ST.SourceTableID inner join SecondJoinTable SJT on      ST.SourceTableID = SJT.SourceTableID where         ST.SourceTableID = X     and JT.ColumnName3 = Y     and JT.Column3 = SJT.Column4 

    One tip, get yourself a copy of SQL Prompt from Red Gate. You can customise the tool to use your desired layout preferences, and then the coders in your shop can all use it to ensure the same coding standards are being adopted by everyone.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want write a query to get the last 24 hours worth of job
I want to get the details of the last run cron job. If the
Last night I tried to put together something that I have had working since
Last year I developed a data access service for our project using Entity Framework
Last evening I did some housekeeping on our code repository - basically moved the
In my last job interview I was asked how to implement a class which
I have a job that runs every night. I do my own logging in
A recent mention of PostSharp reminded me of this: Last year where I worked,
I have the source for a large (>250 files) library that makes heavy use
During last week I received some code and was asked to improve the performance.

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.