SQL tips: quickly and easily get the number of records for each table in your database

Source: Internet
Author: User

However, to obtain the number of records for all tables in a database, you would be exhausted by using the above method. Haha
The following describes how to use the sysindexes and sysobjects tables to obtain the number of records in each table of a database:
First, the SQL Server 2000 version is provided:
Copy codeThe Code is 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 statements of SQL Server2005/8:
Copy codeThe Code is 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. It must have the same result as your count.

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.