Click here to Skip to main content
15,887,821 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Guys,

I have 100 tables in my database. Now i want all the table names which has more then 10 records. But i don't want to check the individual tables every time. So please help me guys.

Thanks in advance and i hope i will get the answer.
Posted
Updated 19-Mar-15 21:23pm
v2
Comments
Maciej Los 20-Mar-15 3:29am    
Wow! Who's a database designer? Why 100 tables? Is there any specific reason?
What have you tried till now?
Hareesh Malli 20-Mar-15 3:38am    
I was designed because i am developing an application. And i have tried in my own way but i couldn't get the result

1 solution

A quick way to do it, to get it from sys.partitions, since directly hitting all tables in db with COUNT(*) can be quite time consuming.

SQL
SELECT OBJECT_SCHEMA_NAME(p.object_id) [Schema]
    , OBJECT_NAME(p.object_id) AS [Table]
    , p.partition_number
    , p.rows AS [Row Count]
FROM sys.partitions p
WHERE OBJECT_SCHEMA_NAME(p.object_id) <> 'sys'
	  AND p.rows > 10
 
Share this answer
 
v2
Comments
Hareesh Malli 20-Mar-15 4:43am    
Awesome answer and thank you bro.......
CHill60 20-Mar-15 6:16am    
5'd!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900