Commenting code is always a good idea and there are more ways than one to comment your code. When running a long series of SQL queries it can be useful to know what has run. If you have conditional statements you’ll want to know which result ran. If you are gathering metrics and have more than a few statements, it helps if you can match the results with the query.
By insering the command Print followed by an identifying phrase between single quotes, you can get this kind of identification on the Messages tab.
Let’s say you don’t use this and have SET STATISTICS IO and SET STATISTICS TIME set. Let’s also say you have 15 queries running in sequence. When you look at the Messages tab, you’re going to have a hard time figuring out what results go with which query, especially since some commands can return multiple sets of statistics. If you do use it and have say PRINT ‘Employee Stats’ before the first query, PRINT ‘Sales figures’ before the second, PRINT ‘Sales by quarter’ before the third and so on, then before the first set of statistics on the Messages tab you’ll see
and before the second set of statistics
and so on. This will not only let you know which stats go with which query, it’ll also let you know if your query is running more processes than you expected.