May 9, 2011 at 12:18 pm
I'm looking for a quick and easy way to identify all tables in a database with a 0(zero) row count and delete them. Anyone have any good ways of doing this?
May 9, 2011 at 12:24 pm
something like this looks like it will work to me:
I'm gneerating a list of tables that are either the HEAP index or the clustered index shows zero rows
SELECT
'DROP TABLE ' + so.[name],
so.[name] as
, CASE
WHEN si.indid between 1 and 254
THEN si.[name]
ELSE NULL
END AS [Index Name]
, si.indid, rows
FROM sys.sysindexes si
INNER JOIN sysobjects so
ON si.id = so.id
WHERE si.indid < 2
--AND so.[name] = @tbname
AND so.type = 'U' -- Only User Tables
AND [rows] = 0
ORDER BY so.[name]
Lowell
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply