formatting T-SQL

  • sqlguy80

    SSCrazy

    Points: 2497

    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

  • jklenk86

    Old Hand

    Points: 388

    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.

  • Jonathan AC Roberts

    SSCoach

    Points: 16489

    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

  • Luis Cazares

    SSC Guru

    Points: 183516

    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
  • Eric M Russell

    SSC Guru

    Points: 124951

    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

  • frederico_fonseca

    SSChampion

    Points: 14037

    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.

  • Luis Cazares

    SSC Guru

    Points: 183516

    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
  • Eirikur Eiriksson

    SSC Guru

    Points: 182336

    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.

  • Jonathan AC Roberts

    SSCoach

    Points: 16489

    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.

  • Grant Fritchey

    SSC Guru

    Points: 395264

    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

    The Scary DBA
    Author of: SQL Server 2017 Query Performance Tuning, 5th Edition and SQL Server Execution Plans, 3rd Edition
    Product Evangelist for Red Gate Software

  • BrainDonor

    SSCoach

    Points: 19155

    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.

    Steve Hall
    Linkedin
    Blog Site

  • Eric M Russell

    SSC Guru

    Points: 124951

    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

  • frederico_fonseca

    SSChampion

    Points: 14037

    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.

  • TUellner

    SSCrazy

    Points: 2324

    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.

  • Joe Torre

    SSChampion

    Points: 10225

    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 48 total)

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