次の方法で共有


Script to List Row Counts of All Tables

Something I had a use for the other day that I thought I would share.  The following script can be run as-is against any SQL Server database, and will list one row per table and give you the row (record) count for each table.  The results are sorted and returned as a single result set instead of multiple result sets as would happen if you used sp_MSforeachtable.  The table count is not based on statistics, but rather based on actual counts.  It uses a dirty read (read uncommitted) so as to not lock the table.  I found this useful in a replication topology where I needed to generate a report comparing the counts between subscribers and publisher (you can use replication validation, but we needed actual counts more for a "sanity check").

List All Table Row Counts.sql

Comments