SQL Code Formatting is very important. Every SQL Server DBA has its own preference about formatting. I like to format all keywords to uppercase. Following are two online tools, which formats SQL Code very good. I tested following script with those tools and I found two of the tools worth mentioning here.
use tempdb go create procedure SP_NonFatal_INSERT @Column2 int =NULL AS declare @ErrorMsgID int insert NonFatal values (@Column2) set @ErrorMsgID =@@ERROR if @ErrorMsgID 0 BEGIN RAISerror ('An error occured updating the NonFatal table',10,1) end GO
Tool 1: Instant SQL Formatter
USE TEMPDB GO CREATE PROCEDURE sp_NONFATAL_INSERT @Column2 INT = NULL AS DECLARE @ErrorMsgID INT INSERT NONFATAL VALUES(@Column2) SET @ErrorMsgID =@@ ERROR IF @ErrorMsgID 0 BEGIN RAISERROR ('An error occured updating the NonFatal table',10,1) END
Tool 2 : SQLinForm
USE tempdb GO CREATE PROCEDURE sp_NonFatal_INSERT @Column2 INT =NULL AS DECLARE @ErrorMsgID INT INSERT NonFatal VALUES (@Column2) SET @ErrorMsgID =@@ERROR IF @ErrorMsgID 0 BEGIN RAISERROR ('An error occured updating the NonFatal table',10,1) END
Both are good tools and still today after many years I use them. If you have come across any other such a great tool, please feel free to add to this blog post.
Reference: Pinal Dave (https://blog.sqlauthority.com)
You can also try Devart’s SQL Formatter Tool – SQL Complete. In SQL Complete 4 its formatting features are much better!
You can read about it and download the free trial version here:
Hey Pinal I’d like to share a PowerShell based formatter (offline) https://deep.data.blog/2013/02/28/t-sql-formatter-a-powershell-script/ which can be useful for command line batch mode formatting.
it is FREE