Created
August 18, 2011 16:23
-
-
Save mwinckler/1154438 to your computer and use it in GitHub Desktop.
sqlserver: find table names having more than X rows
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
/* | |
Find all tables having more than X rows | |
----- | |
Prints table name if the table has more than @minRows rows | |
Replace #{DBNAME} with database name | |
Edit (or remove) where clause as desired | |
*/ | |
select 'declare @name varchar(50), @ct int, @minRows int; | |
set @minRows = 0;' | |
union | |
select 'select @name = ''' + [name] + ''', @ct = count(*) | |
from ' + [name] + ' | |
having count(*) > @minRows; | |
if @ct > 0 print @name; | |
set @ct = 0; | |
set @name = null;' | |
from #{DBNAME}.sys.tables t | |
where | |
[name] like 'sb_tmp%' | |
or [name] like 'sb2_tmp%' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment