377
If you’re looking to quickly gather important information on the tables in your SQL Server database, this T-SQL script is a simple and efficient way to do so. By using this script, you can easily retrieve the row count for each table in the database. With just a few minor modifications, you can customize the script to fit your specific needs. This tool can be especially helpful for anyone who needs to monitor or analyze data in their SQL Server database. Give it a try to see how it can streamline your database management and improve your workflow.
T-Sql
--------------------------------------------------------------------------------------
-- This script retrieves row count information for all tables in a SQL Server database
--------------------------------------------------------------------------------------
SELECT
SCHEMA_NAME(schema_id) AS [SchemaName]
, so.[name] AS TableName
, SUM(sp.[Rows]) AS [RowCount]
FROM
SYS.OBJECTS so
INNER JOIN SYS.PARTITIONS sp
ON so.object_id = sp.object_id
WHERE
so.[type] = 'U'
AND so.is_ms_shipped = 0x0 --0x0 is good as 0
AND sp.index_id < 2
--AND so.[name] NOT IN('tablename here') -- modify this line to filter the result
GROUP BY
so.schema_id
, so.[name]
ORDER BY
--3 DESC,
1,
2
/* To use this script, simply copy and paste it into a new query window in SQL Server Management Studio,
then execute the script to view the row count information for each table in the database. */
/* You can customize the script by modifying the WHERE clause to exclude specific tables,
or by adding or removing columns in the SELECT statement to fit your specific needs. */