The most efficient SQL statement for viewing RowCount of all tables in SQL Server

Source: Internet
Author: User
Tags rowcount

-- Shows all user tables and row counts for the current database

-- Remove OBJECTPROPERTY function call to include system objects

SELECT o.NAME,

i.rowcnt

FROM sysindexes AS i

INNER JOIN sysobjects AS o ON i.id = o.id

WHERE i.indid < 2

AND OBJECTPROPERTY(o.id, 'IsMSShipped') = 0

ORDER BY o.NAME

Note:

The sysindexes system table will be deleted in the future SQL Server. Therefore, we recommend that you replace SQL 2005 and 2008 with the following DMV:

-- Shows all user tables and row counts for the current database

-- Remove is_ms_shipped = 0 check to include system objects

-- i.index_id < 2 indicates clustered index (1) or hash table (0)

SELECT o.name,

ddps.row_count

FROM sys.indexes AS i

INNER JOIN sys.objects AS o ON i.OBJECT_ID = o.OBJECT_ID

INNER JOIN sys.dm_db_partition_stats AS ddps ON i.OBJECT_ID = ddps.OBJECT_ID

AND i.index_id = ddps.index_id

WHERE i.index_id < 2

AND o.is_ms_shipped = 0

ORDER BY o.NAME

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.