SQL Server user data table size statistics

Source: Internet
Author: User
Statistics on the size of SQL Server user data tables (including the total number of records and space usage) in SQL Server, a simple combination of sp_spaceused and sp_msforeachtable stored procedures, you can easily calculate the size of the user data table, this includes the total number of records and space usage. It is very practical and has been tested in both sqlserver2k and sqlserver2005.

/**/ /*
1. Exec sp_spaceused 'table name' (SQL statistics, which may be inaccurate after a large number of transaction operations)
2. Exec sp_spaceused 'table name', true (update the table space size, accurate empty table size, but it may take some time)
3. Exec sp_spaceused (database size query)
4. Exec sp_msforeachtable "Exec sp_spaceused '? '"(All user tablespace tables are small, SQL statistics, and may be inaccurate after a large number of transaction operations)
5. Exec sp_msforeachtable "Exec sp_spaceused '? ', True "(all user tablespace tables are small, and large databases are used with caution)
*/

Create   Table # T (name Varchar ( 255 ), Rows Bigint , Reserved Varchar ( 20 ), Data Varchar ( 20 ), Index_size Varchar ( 20 ), Unused Varchar ( 20 ))
Exec Sp_msforeachtable" Insert   Into # T Exec Sp_spaceused ' ? ' "
Select   *   From # T
Drop   Table # T


In addition, sp_msforeachdb can traverse all databases. For more information, see SQL help.

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.