SQL query table size rows and usage space

Source: Internet
Author: User
Tags getdate reserved
DECLARE @D datetimeset @d=getdate () SET NOCOUNT on EXEC sp_msforeachtable @PRECOMMAND =n ' CREATE table # # (ID INT IDENTITY, table name SYSNAME, number of fields int, record number int, reserved space NVARCHAR (20), use space varchar (20), Index uses space varchar (20), unused space varchar () ', @COMMAND1 =n ' INSERT # # (table name, number of records, reserved space, use space, index use space, unused space) EXEC sp_spaceused "?        " UPDATE # # Number of SET fields = (SELECT COUNT (*) from syscolumns WHERE id=object_id ('? ')) WHERE id=scope_identity () ', @POSTCOMMAND =n ' select * from # # ORDER by record number DESC DROP TABLE # # ' SET NOCOUNT OFF SELECT [statement Run takes time (ms)]=datediff (Ms,@d,getdate ())

SQL query table size rows and usage space

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.