locked
Find Row Count in Table RRS feed

  • Question

  • how to find Row count of a table in sql server ?
    Wednesday, December 24, 2014 1:50 AM

Answers

  • u can use following query 


    SELECT OBJECT_NAME(OBJECT_ID) TableName, st.row_count
    FROM sys.dm_db_partition_stats st
    WHERE index_id < 2
    ORDER BY st.row_count DESC
    • Marked as answer by CarlosVelaZen Friday, December 26, 2014 1:32 AM
    Wednesday, December 24, 2014 1:59 AM

All replies

  • u can use following query 


    SELECT OBJECT_NAME(OBJECT_ID) TableName, st.row_count
    FROM sys.dm_db_partition_stats st
    WHERE index_id < 2
    ORDER BY st.row_count DESC
    • Marked as answer by CarlosVelaZen Friday, December 26, 2014 1:32 AM
    Wednesday, December 24, 2014 1:59 AM
  • how to find Row count of a table in sql server ?

    Check out for couple of options in the below link:(Check the explanations as well)

    http://www.brentozar.com/archive/2014/02/count-number-rows-table-sql-server/

    Wednesday, December 24, 2014 2:06 AM
    Answerer
  • Simply

    SELECT COUNT(*) FROM table

    Another way is using sys.dm_db_partition_stats

    http://msdn.microsoft.com/en-IN/library/ms187737.aspx

    query will look like

    SELECT t.name      AS [TABLE NAME], 
           ps.row_count AS [ROWCOUNT] 
    FROM   sys.tables t
    INNER JOIN sys.dm_db_partition_stats ps
    ON ps.object_id = t.object_id 
    AND ps.index_id < 2 

    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    ----------------------------
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

    • Proposed as answer by Donghui Li Thursday, December 25, 2014 6:06 AM
    Wednesday, December 24, 2014 5:55 AM
  • As alternative you can right click on the table and then properties. There is a property named storage and on the right tab you can see a numbers of the rows that a table contains

    Best Regards,Uri Dimant SQL Server MVP, http://sqlblog.com/blogs/uri_dimant/

    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting: Large scale of database and data cleansing
    Remote DBA Services: Improves MS SQL Database Performance
    SQL Server Integration Services: Business Intelligence

    Wednesday, December 24, 2014 6:04 AM
  • Please check the below mention script.

    DECLARE@TableName sysname

    SET @TableName = 'your table name'
      
    SELECT OBJECT_NAME(object_id), SUM(row_count) AS rows
    FROM sys.dm_db_partition_stats
    WHERE object_id = OBJECT_ID(@TableName)
    AND index_id < 2
    GROUP BY OBJECT_NAME(object_id);

    Thanks

    Wednesday, December 24, 2014 6:08 AM
  • Simple use the aggregate function count() .

    The COUNT(*) function returns the number of records in a table:
    
    
    SELECT COUNT(*) FROM table_name;


    Ahsan Kabir Please remember to click Mark as Answer and Vote as Helpful on posts that help you. This can be beneficial to other community members reading the thread. http://www.aktechforum.blogspot.com/


    Wednesday, December 24, 2014 11:00 PM