SQL-query that finds the table that contains most rows in the database

Viewed 3631

So as the title says i need a query that finds the table that contains most rows in my database.

I can show all my tables with this query:

select * from sys.tables

Or:

select *
from sysobjects
where xtype = 'U'
order by name

And all the indexes with this query:

select *
from sys.indexes

But how do i show the columns with most rows in the whole database?

Kind regards, Chris

3 Answers

You may also use this query to get no duplicates in table names:

Use[DataBase_Name]
select max(i.rows) as recordCounts,t.name as table_name, 
SCHEMA_NAME(t.schema_id) as schema_name from sysindexes i
inner join sys.tables t
on i.id=object_id
group by t.name, SCHEMA_NAME(t.schema_id)
Related