How can you quickly know the size of each table in a database?
Source: Internet
Author: User
Data | database sp_spaceused
Displays the number of rows, the reserved disk space, and the disk space used by the tables in the current database, or the disk space that is reserved and used by the entire database.
is the name of the table for which to request space usage information (reserved and allocated space). The objname data type is nvarchar (776) and the default setting is NULL.
[@updateusage =] ' Updateusage '
Indicates whether the DBCC updateusage should be run within the database (when no objname is specified) or on a specific object (when objname is specified). The value can be true or false. The updateusage data type is varchar (5) and the default setting is FALSE.
Return code value
0 (Success) or 1 (failed)
Result set
If objname is omitted, two result sets are returned.
Column name Data type description
database_name varchar (18) The name of the current database.
Database_size varchar (18) The size of the current database.
Unallocated spaces varchar (18) Unallocated space for the database.
Column name Data type description
Reserved varchar (18) The total amount of space reserved.
The total amount of space used by data varchar (18).
Index_size varchar (18) The space used by the index.
Unused varchar (18) The amount of unused space.
If you specify a parameter, the following result set is returned.
Column name Data type description
Name nvarchar (20) is the name of the table for which the information is requested for space use.
Rows char (one) objname the number of existing lines in the table.
Reserved varchar (18) is the total amount of space reserved for the objname table.
The amount of space used by data varchar (objname) in the table.
The amount of space used by the index in the index_size varchar (objname) table.
Unused varchar (objname) The amount of unused space in the table.
Comments
Sp_spaceused calculates the amount of disk space used by data and indexes and the amount of disk space used by tables in the current database. If there is no given objname,sp_spaceused, the space used by the entire current database is reported.
When you specify Updateusage, Microsoft? SQL Server? Scan the data pages in the database and make any necessary corrections to the sysindexes table for the storage space used by each table. For example, when you drop an index, the sysindexes information for the table may not be current. The process may take some time to run on a large table or database. You should use this process only if you suspect that the value returned is incorrect and that the process has no negative impact on other users or processes in the database. If you prefer this process, you can run DBCC updateusage alone.
Permissions
Execute permissions are granted to the public role by default.
Example
A. Space information on the table
The following example reports the amount of space allocated (reserved) for the titles table, the amount of space used by the data, the amount of space used by the index, and the amount of unused space reserved by the database object.
Use pubs
EXEC sp_spaceused ' titles '
B. Updated space information about the entire database
The following example outlines the space used by the current database and uses the optional parameter @updateusage.
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