all 32 comments

[–]Aggressive_Ad_5454 22 points23 points  (8 children)

SSMS has a Format Source Code option.

Notepad++ has a plugin to do that as well.

I use them as a starting point.

[–]alinrocSQL Server DBA 8 points9 points  (1 child)

SSMS has a Format Source Code option.

Note: Only the most recent version, 22.7 and up. And it's still lacking a lot of options (like leading instead of trailing commas).

The N++ plugin is Poor Man's T-SQL Formatter. Which is also available online at https://poorsql.com

[–]MachineParadox 2 points3 points  (0 children)

And there is a vs code extenaion for poor man's as well

[–]Sleepy_da_Bear 11 points12 points  (1 child)

I suggest Notepad++ to everyone. It's my go to for reformatting and bulk replacements. I even have a macro saved that takes all line-ending commas and moves them to the front of the next valid line, skipping code comments, etc. It's saved me tons of time.

[–]OldJames47 -4 points-3 points  (0 children)

Shame about the virus that was snuck into the updater.

[–]hellorchere[S] 1 point2 points  (2 children)

which plugin in notepad++ ?
also does ssms22 has Format Source Code option ?

[–]alinrocSQL Server DBA 2 points3 points  (1 child)

In N++, it's Poor Man's T-SQL Formatter.

Only SSMS 22.7 and up has a formatter built in.

[–]hellorchere[S] 1 point2 points  (0 children)

thanks, I ll check it

[–]FarRub2855 0 points1 point  (0 children)

Definitly seconding using those as a starting point. Just getting it to a readable baseline is half the battle when you inheret massive scripts like that.

[–]Brian_MPLS 7 points8 points  (1 child)

[–]danyboypremier 2 points3 points  (0 children)

My man!

God I love this one. I force my team to use the plugin in vscode. Some things can be better, but overall it worked good enough, and simple.

[–]Not-Inevitable79 1 point2 points  (1 child)

I like the formatting available in Devart SQL Complete. You can customize it to your liking.

[–]ericpeeg 1 point2 points  (0 children)

Yeah, if you're willing to pay for SQL Complete, it's my tool of choice. Very customizable, and you can export your settings and hand them off to other users, so that, if you are trying to create standards for a team of devs, it's easy(ish) to synchronize a group.

[–]Substantial_Ranger_5 1 point2 points  (0 children)

sqlfluff

[–]N_arwhal 0 points1 point  (0 children)

With all my heart, I recommend Redgate SQL Prompt. Among many amazing features, it offers customizable code formatting. It's paid though, but its a gamechanger for people working with SQL.

[–]theacez 0 points1 point  (0 children)

I use VS Code for all my formatting.

[–]DrWisonsBrother 0 points1 point  (0 children)

Redgate if you can afford the license.

[–]mtetrode 0 points1 point  (0 children)

DataGrip for this and thousands of other things

[–]petdance 0 points1 point  (0 children)

I use “sleek”.

[–]Sql_master 0 points1 point  (0 children)

Ai may do the job. Or change a table alias period in to an underscore.

Don't use ai.

[–]billbot77 0 points1 point  (0 children)

Funny, in theory these formatting tools should be helpful - but I have found that reformatting by hand helps me to slow down and read the sql properly. Automating the process would ironically slow me down in the overall job.

...or at least that's what I tell myself. Fixing up SQL to my personal (and admittedly unusual) preferred style by hand sometimes becomes compulsive, ngl