Dennis Bottjer | ASP.NET + SharePoint Architect, Trainer & Speaker

"An Ounce of Prevention is Worth a Pound of Cure" - Ben Franklin
posts - 168, comments - 59, trackbacks - 41

My Links

News

Add to Technorati Favorites The views expressed in this blog are mine and mine alone, not that of my employer, Microsoft, or anyone else’s. No warrantee is given for the quality of any material on this site.

Tag Cloud

Archives

Post Categories

SQL Formatting for Easier Debugging

1
2
3
4
5
6
SELECT [IssueHistoryID]
,[StafferID]
,[IssueID]
,[Comment]
,[DateCreated]
FROM [IssueVision].[dbo].[IssueHistory]

This Simple query was created from a demo Microsoft Smart Client Application called IssueVision.  To create it I right clicked on IssueHistory table in SQL Server Management Studio 2005.  Notice the commas are all to the left of the column names.  Commonly, I see queries written like this instead:

1
2
3
4
5
6
SELECT [IssueHistoryID],
[StafferID],
[IssueID],
[Comment],
[DateCreated]
FROM [IssueVision].[dbo].[IssueHistory]

The first example with the commas on the left is faster to debug and modify. Notice the only modification I need  to make to comment out a column/line is to place "--" in front of the comma as shown below.

1
2
3
4
5
6
SELECT [IssueHistoryID]
,[StafferID]
,[IssueID]
,[Comment]
--,[DateCreated]
FROM [IssueVision].[dbo].[IssueHistory]

I realize this tip is a subtle point.  Seems a little strange that I'm actually analizing the placement of a comma.  However, I have become quite fond of this style b/c it saves time and helps me to reduce simple syntax mistakes while testing/debugging large sprocs.  Try it with some more complex SQL and see what you think.

Print | posted on Saturday, October 21, 2006 6:03 AM | Filed Under [ SQL & LINQ ]

Feedback

Gravatar

# re: SQL Formatting for Easier Debugging

i've utilized this a lot and it works quite well for mssql stuff. also, putting joins on their own lines helps for troubleshooting sometimes too.
10/23/2006 3:19 AM | royashbrook
Comments have been closed on this topic.

Powered by: