SQLTeam.com | Weblogs | Forums

Get list of tables with rows

Hello,
in a SQL SERVER 2019 database, I have several thousands of tables.
Is there a way to get the list of only tables with data? (at least 1 row).

Thank you.

Luis

hi

hope this link helps :slight_smile:

if you can understand and implement .. that's good

if you need help with the SQL please let me know !!

hi

another query

select schema_name(tab.schema_id) + '.' + tab.name as [table]
   from sys.tables tab
        inner join sys.partitions part
            on tab.object_id = part.object_id
where part.index_id IN (1, 0) -- 0 - table without PK, 1 table with PK
group by schema_name(tab.schema_id) + '.' + tab.name
having sum(part.rows) > 0
order by [table]
1 Like

Perfect, thank you Harish.

L.