Querying the size of a table in a SQL database

Source: Internet
Author: User

Recently when doing a system maintenance for a customer, you need to look at the size of the database table, the related SQL is as follows:

Select the database to be checked and execute the following statement in the top left drop-down box

1. exec sp_spaceused ' table name '-(SQL statistics, may not be allowed after a large number of transactional operations)
2. exec sp_spaceused ' table name ', True--(exact table space size, but may take some time to count)
3. Exec sp_spaceused--(Database size query)
4. Exec sp_msforeachtable "exec sp_spaceused '?" --(all user tablespace tables are small, SQL statistics, and may not be allowed after a large number of transaction operations)
5. Exec sp_msforeachtable "exec sp_spaceused '", true "--(all user tablespace tables are small, big databases are used with caution)


CREATE table #t (name varchar (255), rows bigint, reserved varchar, data varchar, index_size varchar, unused var char (20))
EXEC sp_msforeachtable "INSERT into #t exec sp_spaceused '? '"
SELECT * from #t
drop table #t

Querying the size of a table in a SQL database

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.