SQL Tips quick and easy to get your database the number of records per table _mssql

Source: Internet
Author: User
But how to get the number of records for all the tables in a database, if you use the above method to estimate the exhaustion. Oh
Here's how to use the sysindexes and sysobjects tables to get the number of records per table in a database:
First give the SQL Server 2000 version:
Copy Code code as follows:

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

SQL SERVER2005/8 version of SQL statement:
Copy Code code as follows:

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

Try it quickly, and you'll get the same result as count (*).

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.