title: Count all rows from all tables in two databases on different servers
body: <p>I would like my query to return the table name, and rowcount for all of the tables on our two reporting servers. They both have the same tables. Also, I already added the linked server the other day between these two.</p>
  
  <p>Query so far for one server, not sure how to add a third column connected with our other server though:</p>
  
  <pre><code>SELECT 
      t.NAME AS TableName,
      p.[Rows]
  FROM 
      sys.tables t
  INNER JOIN      
      sys.indexes i ON t.OBJECT_ID = i.object_id
  INNER JOIN 
      sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id
  INNER JOIN 
      sys.allocation_units a ON p.partition_id = a.container_id
  WHERE 
      t.NAME NOT LIKE 'dt%' AND
      i.OBJECT_ID &gt; 255 AND   
      i.index_id &lt;= 1
  GROUP BY 
      t.NAME, i.object_id, i.index_id, i.name, p.[Rows]
  ORDER BY 
      object_name(i.object_id) 
  </code></pre>
  
  <p><strong>Desired output:</strong></p>
  
  <pre><code>TableName   DB1_rows     DB2_Rows
  ----------+-----------+-----------
  Account   |  20,000   |  19,388
  Contacts  |   1,234   |   1,390
  Bla       |   2,330   |   2,430
  </code></pre>