Skip to content

Commit

Permalink
GetPartitionRowTallies
Browse files Browse the repository at this point in the history
  • Loading branch information
jamiet committed Dec 30, 2013
1 parent 944a49e commit 5c9314e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
1 change: 1 addition & 0 deletions TSQLCodeLibrary/TSQLCodeLibrary.sqlproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
<Build Include="jt\Stored Procedures\GetTableRowTallies.sql" />
<Build Include="jt\Stored Procedures\TableStats.sql" />
<Build Include="jt\Stored Procedures\AllPermissions.sql" />
<Build Include="jt\Stored Procedures\GetPartitionRowTallies.sql" />
</ItemGroup>
<ItemGroup>
<ArtifactReference Include="$(DacPacRootPath)\Extensions\Microsoft\SQLDB\Extensions\SqlServer\110\SqlSchemas\master.dacpac">
Expand Down
17 changes: 17 additions & 0 deletions TSQLCodeLibrary/jt/Stored Procedures/GetPartitionRowTallies.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
CREATE PROCEDURE jt.GetPartitionRowTallies
@dbName SYSNAME = 'master'
AS
BEGIN
DECLARE @sql NVARCHAR(MAX) = '
SELECT t.name
,s.partition_number
,s.row_count
FROM [@dbname].sys.dm_db_partition_stats AS s
INNER JOIN [@dbname].sys.tables AS t ON t.[object_id] = s.[object_id]
GROUP BY t.name
,s.partition_number
,s.row_count;
';
SET @sql = REPLACE(@sql,'@dbName',@dbName)
EXEC (@sql)
END
22 changes: 10 additions & 12 deletions TSQLCodeLibrary/jt/Stored Procedures/GetTableRowTallies.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@
@dbName SYSNAME = 'master'
AS
BEGIN
DECLARE @sql NVARCHAR(MAX) = '
SELECT t.name
,s.partition_number
,s.row_count
FROM [@dbname].sys.dm_db_partition_stats AS s
INNER JOIN [@dbname].sys.tables AS t ON t.[object_id] = s.[object_id]
GROUP BY t.name
,s.partition_number
,s.row_count;
';
SET @sql = REPLACE(@sql,'@dbName',@dbName)
EXEC (@sql)
CREATE TABLE #t (
name sysname
, partition_number int
, row_count int
);
INSERT #t
EXEC jt.GetPartitionRowTallies @dbName = @dbName;
SELECT name,row_count = SUM(row_count)
FROM #t
GROUP BY name;
END

0 comments on commit 5c9314e

Please sign in to comment.