Other: Total Record Counts
The following SQL script will count all records in all tables in a database.
- DECLARE @TableRowCounts TABLE ([TableName] VARCHAR(128), [RowCount] INT) ;
- INSERT INTO @TableRowCounts ([TableName], [RowCount])
- EXEC sp_MSforeachtable 'SELECT ''?'' [TableName], COUNT(*) [RowCount] FROM ?' ;
- SELECT
- [TableName], [RowCount]
- FROM
- @TableRowCounts
- WHERE
- [RowCount] > 0
- ORDER BY
- [TableName]
- SELECT
-
SUM([RowCount]) as 'Total Records'
- FROM
- @TableRowCounts
Related Articles
Audit Scripts: Row Counts and Progress Monitoring
This article shows you a script that can be used to monitor the progress of both a Backup and a Restore. It can also be used to just review row counts on all the Universal Database tables. The first code block is used to populate a SQL Server Temp ...
Other: Obtaining Record Counts for all Tables
The following script will count all records in all tables. DECLARE @TableRowCounts TABLE ( [TableName] VARCHAR(128), [Action_Group] INT, [Incomplete] INT, [Complete] INT, [Total] INT ) ; INSERT INTO @TableRowCounts ( [TableName], [Action_Group], ...
Audit Scripts: Activity Billed/Unbilled row counts
After you have backed up financial information like Time Entries, Expense Entries, and Fee Entries it is a good idea to audit the results prior to restoring data to the destination system. For example, some Universal Destinations support restoring ...
Delta Compare Two Backups
Sometimes, you may want to do an Alpha/Delta compare of two backups of a firms data. This can allow you to spot data trends and changes over time. ...
Clear all Result_Ids
/* WARNING!!! THIS IS A DANGEROUS SCRIPT!!! MAKE SURE YOU ARE USING THE RIGHT DATABASE!!! This script will clear out all Result_Ids in a database. */ USE [DATABASENAME]; EXEC sp_MSforeachtable 'UPDATE ? SET Action_Group = 5000, Action_Priority = ...