As you might know I’m really picky when it comes to formatting code… heck, I event wrote a book on it! This even extends to T-SQL. I have worked at companies that had stored procedures that were formatted so poorly that I could not follow it at all. Thankfully I found a very cool web site called Instant SQL Formatter that does all the work for me… instantly! It will format T-SQL like this (generated by SQL Server Management Studio):
USE [Acme] GO IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].EventLog_DeleteOld') AND type in (N'P', N'PC')) DROP PROCEDURE [dbo].EventLog_DeleteOld GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE PROCEDURE [dbo].EventLog_DeleteOld AS BEGIN DELETE FROM EventLog WHERE ([TimeStamp] < GETDATE() - 14) END GO
To this:

Very nice! There are lots of options (the T-SQL was formatted with “Function Case” set to “Unchanged”).
Tip Submitted By: David McCarter
Discover more from dotNetTips.com
Subscribe to get the latest posts sent to your email.
