Last active
October 25, 2018 17:32
-
-
Save ronnysuero/10d0434c89df328af251d3d13cb176e0 to your computer and use it in GitHub Desktop.
Total Rows By Table Sql Server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WITH UnUsedTables ( | |
TableName | |
,TotalRowCount | |
,CreatedDate | |
,LastModifiedDate | |
) | |
AS ( | |
SELECT DBTable.NAME AS TableName | |
,PS.row_count AS TotalRowCount | |
,DBTable.create_date AS CreatedDate | |
,DBTable.modify_date AS LastModifiedDate | |
FROM sys.all_objects DBTable | |
JOIN sys.dm_db_partition_stats PS ON OBJECT_NAME(PS.object_id) = DBTable.NAME | |
WHERE DBTable.type = 'U' | |
AND NOT EXISTS ( | |
SELECT OBJECT_ID | |
FROM sys.dm_db_index_usage_stats | |
WHERE OBJECT_ID = DBTable.object_id | |
) | |
) | |
-- Select data from the CTE | |
SELECT TableName | |
,TotalRowCount | |
,CreatedDate | |
,LastModifiedDate | |
FROM UnUsedTables | |
ORDER BY TotalRowCount ASC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment