1. sp_spaceused
Calculates the amount of disk space used by the data and index and the amount of disk space used by the tables in the current database. If no objname is given,sp_spaceused reports the space used by the entire current database.
Grammar
sp_spaceused [[@objname =] 'objname']
[,[@updateusage =] 'updateusage']
Example:
EXEC sp_spaceused Tbl1000,true
If objnameis 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 space |
varchar (18) |
Unallocated space for the database. |
Column Name |
Data Type |
Description |
Reserved |
varchar (18) |
The total amount of space reserved. |
Data |
varchar (18) |
The total amount of space used by the data. |
Index_size |
varchar (18) |
The space used by the index. |
Unused |
varchar (18) |
The amount of unused space. |
2. sys.dm_db_index_physical_stats
Returns the size and fragmentation information for the data and indexes of the specified table or view. Grammar
Sys.dm_db_index_physical_stats ( {database_id | NULL | 0 | DEFAULT} , {object_id | NULL | 0 | DEFAULT} , {index_id | NULL | 0 | -1 | DEFAULT} , {partition_number | NULL | 0 | DEFAULT} , {mode | NULL | DEFAULT})
Example
SELECT Index_type_desc, Alloc_unit_type_desc, Index_depth, Page_count, Record_countfrom Sys.dm_db_index_physical_ Stats (db_id (), object_id (' dbo. Tbl1000 '), Null,null, ' SAMPLED ');
Msdn:https://msdn.microsoft.com/zh-cn/library/ms188917%28v=sql.105%29.aspx
SQL Server View table information