title: Get number of rows for tables across all databases
body: <p>Searched a bit and didn't see anything that really fit my needs (although I don't really understand SQL beyond the basic select statement so maybe I just missed it). Took a SQL class in school many moons ago.</p>
  
  <p>I have:</p>
  
  <ul>
  <li>Virtual Windows Server 2008 R2 running SQL 2008 R2. I connect via MS SQL Server Management Studio</li>
  <li>90-100 databases</li>
  <li>All DB's have the same table structure (each one is a different client)</li>
  </ul>
  
  <p>I want to:</p>
  
  <ul>
  <li>Search all databases and return a list of all databases which have a table (TableName) that is larger than say, 5000 records.</li>
  <li>Some sort of script that I can schedule that will use that list and if it finds a DB that the TableName table is more than 5000 records, will delete anything older than x amount of days (say 30). Any kind of logging to know what happened over the last few days would be a bonus.</li>
  </ul>
  
  <p>Any help would be appreciated. Thank you.</p>
  
  <p>EDIT/UPDATE (2/24/15): Hiren Dhaduk provided a nice stored procedure that works. Thanks!</p>