There are couple ways to count row of a SQL table. Below is the quickest script to do that.
1 2 | USE [YourDatabaseName]
SELECT COUNT (*) AS "TotalRow" FROM [YourTableName]
|
As an alternative, we can use dynamic management view sys.dm_db_partition_stats.1 2 3 4 5 6 7 | USE [YourDatabaseName]
DECLARE @TableName sysname
SET @TableName = 'YourTableName'
SELECT OBJECT_NAME ( OBJECT_ID ) AS "TableName" , SUM (row_count) AS "TotalRow"
FROM sys.dm_db_partition_stats
WHERE OBJECT_ID = OBJECT_ID (@TableName) AND index_id < 2
GROUP BY OBJECT_NAME ( OBJECT_ID );
|
No comments:
Post a Comment