How do I see how much space each table occupies in the SQL Server database?
To create a stored procedure:
CREATE PROCEDURE [dbo]. [Sys_viewtablespace]
As
BEGIN
SET NOCOUNT on;
CREATE TABLE [dbo]. #tableinfo (
Table name [varchar] (COLLATE) chinese_prc_ci_as NULL,
Number of records [INT] NULL,
reserved space [varchar] (COLLATE) chinese_prc_ci_as NULL,
Use space [varchar] (COLLATE) chinese_prc_ci_as NULL,
index occupy space [varchar] (COLLATE) chinese_prc_ci_as NULL,
unused space [varchar] (COLLATE) chinese_prc_ci_as NULL
)
INSERT into #tableinfo (table name, number of records, reserved space, use space, index occupy space, unused space)
exec sp_msforeachtable "exec sp_spaceused '?"
SELECT * FROM #tableinfo
ORDER BY record number desc
drop table #tableinfo
END
When used directly: Exec sys_viewtablespace
How do I see how much space each table occupies in the SQL Server database?