formatting T-SQL

  • Hi,

    I found one formatter online, but wanted to know if you use any tools to format the T-SQL code , before releasing it.
    Thanks

  • I use the Poor SQL SSMS plugin. Works pretty well, and keeps things consistent. I'm not in love with all it's formatting decisions, but consistency is best.

  • sqlguy80 - Thursday, August 2, 2018 10:02 AM

    Hi,

    I found one formatter online, but wanted to know if you use any tools to format the T-SQL code , before releasing it.
    Thanks

    I've tried ApexSQL. They have a free SQL code formatter that's an addin to SSMS.
    It's pretty good, you can customise the output to get nearly any formatting you desire. https://www.apexsql.com/sql_tools_refactor.aspx

  • I have used PoorSQL on the web and have installed ApexSQL Refactor. They both do a decent job for free tools. You could also try SSMS Tools Pack.
    I'm currently using RedGate Prompt and it has lots of features.
    I suggest that you try each of them and compare them to find what you prefer.
    I personally believe that format shouldn't be left to tools and it should be something that comes from the developers in the first place (using team standards).

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • I'd rather not be pasting T-SQL code to the web just to format it. RedGate's 'SQL Prompt', a plugin for SSMS, has a Format SQL option that works well.

    "Do not seek to follow in the footsteps of the wise. Instead, seek what they sought." - Matsuo Basho

  • Free versions already mentioned.
    For paid versions
    RedGate - SQL Prompt 
    DevArt - SQL Complete
    Neither completely good, one better on particular things, the other better on other things. DevArt a lot cheaper than RedGate.

  • Eric M Russell - Thursday, August 2, 2018 2:48 PM

    I'd rather not be pasting T-SQL code to the web just to format it. RedGate's 'SQL Prompt', a plugin for SSMS, has a Format SQL option that works well.

    You don't need to paste T-SQL code on the web. Poor SQL has an SSMS plug-in that works offline.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • sqlguy80 - Thursday, August 2, 2018 10:02 AM

    Hi,

    I found one formatter online, but wanted to know if you use any tools to format the T-SQL code , before releasing it.
    Thanks

    My suggestion is to write the code in the proper format in the first place.
    😎

    If the code is properly formatted, there errors are less likely as it is more readable, if aligned for columnar editing, then that's a big bonus as it makes each snippet more reusable.
    It may take slightly more time to write the code but it can safe hours of work.

  • Eirikur Eiriksson - Friday, August 3, 2018 3:04 AM

    sqlguy80 - Thursday, August 2, 2018 10:02 AM

    Hi,

    I found one formatter online, but wanted to know if you use any tools to format the T-SQL code , before releasing it.
    Thanks

    My suggestion is to write the code in the proper format in the first place.
    😎

    If the code is properly formatted, there errors are less likely as it is more readable, if aligned for columnar editing, then that's a big bonus as it makes each snippet more reusable.
    It may take slightly more time to write the code but it can safe hours of work.

    I often have to edit someone else's SQL that's almost unreadable due to its formatting (or non-formatting) a formatting tool takes away many minutes of manual effort and over a year many hours.

  • I do love me some SQL Prompt from Redgate Software. It does more than just format the code. It also provides type-ahead, supports Azure SQL Database and Managed Instances, has code analysis, snippets, more. It's a very complete method for programming T-SQL, not just a formatter.

    I loved it even before I went to work for them. Yes, I work for them.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Yes, SQL Prompt. I've used it in every company I've worked for as a DBA - even if I'd had to persuade them to buy it.
    Currently trying to get my current employer to purchase Toolbelt and if they don't I'll buy SQL Prompt for myself. Then they can all watch and weep.

  • Eirikur Eiriksson - Friday, August 3, 2018 3:04 AM

    sqlguy80 - Thursday, August 2, 2018 10:02 AM

    Hi,

    I found one formatter online, but wanted to know if you use any tools to format the T-SQL code , before releasing it.
    Thanks

    My suggestion is to write the code in the proper format in the first place.
    😎

    If the code is properly formatted, there errors are less likely as it is more readable, if aligned for columnar editing, then that's a big bonus as it makes each snippet more reusable.
    It may take slightly more time to write the code but it can safe hours of work.

    Even better, you can enforce your T-SQL formatting standard using SQL Server's policy-based management. Don't even let the developer save their  procedures and views until they're properly formatted. :Whistling:

    "Do not seek to follow in the footsteps of the wise. Instead, seek what they sought." - Matsuo Basho

  • Eric M Russell - Friday, August 3, 2018 8:25 AM

    Even better, you can enforce your T-SQL formatting standard using SQL Server's policy-based management. Don't even let the developer save their  procedures and views until they're properly formatted. :Whistling:

    Got examples of this? Would be interested as not aware it was possible.

  • I really like Redgate SQL Prompt. With some of the horrendous T-SQL code I inherit, it makes my life a lot easier. Sometimes I just reformat a section of code but a lot of times on the really bad stuff, I just reformat the whole deal.

  • I use Red-Gate SQL Prompt. It has some nice enhanced Intellisence like functionality I really like. It collects Meta data when you connect to a linked server. It fills in column lists and a lot of other functionality as well as formatting.

Viewing 15 posts - 1 through 15 (of 47 total)

You must be logged in to reply to this topic. Login to reply