Within MySql Workbench, there’s a feature called “Clean Up SQL” which automatically tidies up your SQL and the indentation automatically.
This is a very useful feature, as your messy SQL then becomes nice and neat. Unfortunately with Microsoft SQL Server Management Studio (SSMS), this feature is not standard.
Luckily I came across the following open source T-SQL formatter library, complete with an add-in for SSMS which adds this functionality – Poor Mans T-SQL Formatter. This plugin automatically formats your SQL, adding tabs and linebreaks etc in order to make it easy to read.
After installing the product, the following folder needs renaming in order to work with the 2014 version of SSMS:
%SystemDrive%\ProgramData\Microsoft\SQL Server Management Studio\11.0
%SystemDrive%\ProgramData\Microsoft\SQL Server Management Studio\12.0
This is due to the installer. The installer puts the files in the incorrect place for the 2014 version of SQL Management Studio. Once you have renamed the folder and restarted SSMS, it will automatically add the options to the Tools menu.
Not only does this plugin work for SQL Management Studio, there are also versions for:
If you don’t wish to install the software, there’s an online version available.