Getting Started with Adobe After Effects - Part 6: Motion Blur


Upload Image Close it
Select File

Hardik Doshi is Technical Lead and systems development professional with iGATE having a total IT experience of more than 7 years. He is MCTS certified professional in SQL Server technology.
Browse by Tags · View All
#SQL Server 3
T-SQL 3
SQL Server 3
Admin 2
IO 2
Query 2
Restore 1
Backup 1
Performance 1
CPU 1

Archive · View All
June 2012 1
May 2012 1
July 2011 1

Get Row Count using SQL Profiler

Jul 3 2011 3:14PM by Hardik Doshi   

When we fire any query in SSMS, it returns data, we generally check status bar/message tab to get the information of the records affected or retrieved.

Do you know SQL Profiler provides facility to capture the record count (ROWCOUNT)?

Though it is small feature and often unnoticed, I would like to describe here. This feature is available since SQL Server 2005.

Sample Database used for this post:

I am using "AdventureWorks2008R2" database - sample database provided by Microsoft SQL Server 2008 R2.

You can download this database from: http://msftdbprodsamples.codeplex.com/

Generally what I do to check affected/retrieved records:
SELECT sp.[StateProvinceID], 
       sp.[StateProvinceCode], 
       sp.[IsOnlyStateProvinceFlag], 
       sp.[Name] AS [StateProvinceName], 
       sp.[TerritoryID], 
       cr.[CountryRegionCode], 
       cr.[Name] AS [CountryRegionName] 
FROM [Person].[StateProvince] sp 
LEFT OUTER JOIN [Person].[CountryRegion] cr 
ON sp.[CountryRegionCode] = cr.[CountryRegionCode];

Query returns 181 rows and status bar displays number of rows retrieved with execution time of the query as shown in the image below:

StatusBar

When we execute query batch (more than one query), stored procedure etc., its difficult to retrieve the record counts of each individual queries if SET NOCOUNT is ON. Here we can take help of SQL Profiler.

Get record count using SQL Profiler:

Start the profiler by selecting following Events:

ProfilerEvents

(For this post, I have selected more events & arranged columns. You can select the events as per your need but needs to include RowCounts column.)

Now, executing the above mentioned same query in SSMS once again and check profiler result, Column RowCounts has the information which I want to know as below:

SingleQueryExecutionProfiler

T-SQL query batch & retrieving affected records:

Now, I am going to execute following T-SQL query batch in SSMS query editor:

SET NOCOUNT ON
BEGIN
DECLARE @countryRegionCode NVARCHAR(10)
DECLARE @personStateCountryData TABLE 
       ( [StateProvinceID] INT, 
         [StateProvinceCode] NVARCHAR(4), 
         [IsOnlyStateProvinceFlag] BIT, 
         [StateProvinceName] NVARCHAR(50), 
         [TerritoryID] INT, 
         [CountryRegionCode] NVARCHAR(4), 
         [CountryRegionName] NVARCHAR(50) ) 

SET @countryRegionCode = 'US'
INSERT INTO @personStateCountryData 
      ( StateProvinceID, 
        StateProvinceCode, 
        IsOnlyStateProvinceFlag, 
        StateProvinceName, 
        TerritoryID, 
        CountryRegionCode, 
        CountryRegionName )
SELECT sp.[StateProvinceID], 
       sp.[StateProvinceCode], 
       sp.[IsOnlyStateProvinceFlag],
       sp.[Name] AS [StateProvinceName],
       sp.[TerritoryID],
       cr.[CountryRegionCode],
       cr.[Name] AS [CountryRegionName] 
FROM [Person].[StateProvince] sp 
LEFT OUTER JOIN [Person].[CountryRegion] cr 
            ON sp.[CountryRegionCode] = cr.[CountryRegionCode] ;

SELECT p.StateProvinceCode,
       p.CountryRegionCode,
       p.CountryRegionName
FROM @personStateCountryData AS p 
WHERE p.CountryRegionCode = 'US' ;
END
GO

SSMS query editor status bar displays 53 rows as expected. But I am not able to get the information of each individual query’s record counts.

That I can see using SQL profiler as below:

QueyBatchExecutionProfiler

We can use filter on RowCounts column same as other columns.

Available filters are: Equals, Not equal to, Greater than or equal, Less than or equal

 

Hope this is helpful. Thanks.

Tags: RowCounts, SQL Profiler, SQL Server, T-SQL, #SQL Server, BRH,


Hardik Doshi
20 · 9% · 2839
2
 
0
Lifesaver
 
 
0
Learned
 
0
Incorrect



Submit

1  Comments  

  • Thanks, Hardik! Profiler has many features, some of which we never know (or never use). Rowcounts is one such feature - I knew it, but never used it myself.

    The next time I use profiler, I will make sure to consciously use the RowCounts column.

    commented on Jul 3 2011 11:41PM
    Nakul Vachhrajani
    4 · 33% · 10680

Your Comment


Sign Up or Login to post a comment.

"Get Row Count using SQL Profiler" rated 5 out of 5 by 2 readers
Get Row Count using SQL Profiler , 5.0 out of 5 based on 2 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]