Created
February 26, 2016 15:00
-
-
Save NoahDragon/830322b4af06cdd2b265 to your computer and use it in GitHub Desktop.
Get Row Count for All Tables in A Database.
This file contains hidden or 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
declare @tableName VARCHAR(256), @id INT, @sql NVARCHAR(MAX) | |
set @id = 0 | |
while(1=1) | |
begin | |
SELECT Top 1 | |
@tableName = name, | |
@id = object_ID | |
FROM sys.objects | |
WHERE name LIKE 'Import%' -- Change to the table you would like to get the count. | |
AND type = 'U' | |
AND object_id > @id | |
ORDER BY object_ID | |
IF @@ROWCOUNT = 0 | |
break | |
SET @sql = 'SELECT ''' + @tableName + ''' AS TableName, COUNT(1) AS CountRow FROM ' + @tableName | |
print @sql | |
EXEC (@sql) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment