How to view statistics for tables and indexes

Source: Internet
Author: User

These days require a server to do statistics, mainly for tables and indexes. Here I'll simply share a few ways to query the data tables and index statistics:

1. Use T-SQL statements to implement:

SelectSchema_name (t.schema_id) as'Architecture', T.name as'Table name', i.rows as'Number of rows',       8* Reserved AS'reserved Space (KB)',       8* Dpages AS'Used (KB)',       8* (Reserved-dpages) as'not Used (KB)' fromSys.tables asT, sysindexes asIwheret.object_id = i.id and I.indid <=1--Select different tables to query and t.name= separately'Cttextdata'

Execution results

The advantages of this approach are as follows:

    • Fast running speed.
    • Without access to the user table, performance is not affected and locks are not added.
    • Flexible combinations, and can also be combined with other statements to query the gold results.

2. Using the system stored procedure sp_spaceused

' ctapplication '

The results of the implementation are as follows:

Note that when you do not join the table name parameter, the result is all the table synthesis information for that context (use xxx--library name) DB instance.

You can use sp_msforeachtable to traverse all tables in the current context

As follows:

It is important to note that when using sp_spaceused, if the schema is dbo, you can not enter the schema, otherwise you must enter your own schema name.

3. Using System reports

Using the process, right-click the DB instance, and then tap reports \ Standard reports \ Disk usage by Top Tables:

Final display:

The figure shows some of the information needed, each of which can be ordered in sequence and flashback, in kilobytes.

At the same time right button in this window, there are changes to page layout, export (excel\word\pdf), printing and other functions.

This approach has the following advantages:

    • The visual interface is easy to operate.
    • No code writing is required.
    • Printing can be exported directly.

Summarize:

This paper briefly introduces several statistics of disk and index of querying database table. In peacetime work will often use this function, because to look at the pressure of the query table, index ratio, has been the use of various tables of space, for the design of the table, the use of indexes, etc. have a great help. We hope to help you.

How to view statistics for tables and indexes

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.