25 December,2014 by Tom Collins
Bad indentation in a stored procedure is inefficient. I receive daily requests to analyse sql queries for performance issues , but quite often I spend the first part of the job applying indentation to make the code easier to read.
I don’t think bad indentation as bad coding and it doesn’t make the code run inefficiently. But it does make troubleshooting a slow running query more difficult. In an earlier post - Stored Procedure Checklist - I highlight a checklist of items which have positive performance impact on the query.
MAKE SQL QUERIES EASIER TO TROUBLESHOOT
When I start analysing the stored procedure , particularly the very long stored procedures, I try to understanding the flow of the code. Quite often other developers have added to the original code – which adds to different styles.
As well as helping others to read the code , it also allows the developer to read their own code , when required to revisit the original code.
Along with good indentation another useful habit is to use Commenting. I prefer a comment block at the top with usage and revision history . Snippets throughout the code to enhance the understanding
As it’s the holiday season , maybe you could consider adding it to your New Year’s resolution list.
SQL Server - Stored Procedures versus ad-hoc paramaterized queries.Which is faster?
Last time a stored procedure was executed - SQL Server DBA
Grant execute on all stored procedures - SQL Server DBA
This is only a preview. Your comment has not yet been posted.
As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.
Having trouble reading this image? View an alternate.
Posted by: |