Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用T-SQL进行sqlserver数据库分析_Sql_Sql Server_Database - Fatal编程技术网

使用T-SQL进行sqlserver数据库分析

使用T-SQL进行sqlserver数据库分析,sql,sql-server,database,Sql,Sql Server,Database,我有一个小应用程序,在SQL Server 2000/2005数据库中有大约38个表。现在我想知道有多少KB/MB的数据不是他们使用T-SQL获取的记录。 用更好的方式说,我想对整个数据库进行分析。可能吗?怎样 谢谢大家,对于整个数据库,您只需运行此 exec sp_helpdb 'YourDatabaseName' 根据表,您可以使用此表+ declare @PageSize float select @PageSize=v.low/1024.0 from master.dbo.spt_va

我有一个小应用程序,在SQL Server 2000/2005数据库中有大约38个表。现在我想知道有多少KB/MB的数据不是他们使用T-SQL获取的记录。 用更好的方式说,我想对整个数据库进行分析。可能吗?怎样
谢谢大家,

对于整个数据库,您只需运行此

exec sp_helpdb 'YourDatabaseName'
根据表,您可以使用此表+

declare @PageSize float
select @PageSize=v.low/1024.0 from master.dbo.spt_values v 
where v.number=1 and v.type='E'

SELECT tbl.name,

ISNULL((select @PageSize * SUM(CASE WHEN a.type <> 1 THEN a.used_pages 
WHEN p.index_id < 2 THEN a.data_pages ELSE 0 END)

FROM sys.indexes as i

JOIN sys.partitions as p ON p.object_id = i.object_id and p.index_id = i.index_id

JOIN sys.allocation_units as a ON a.container_id = p.partition_id

where i.object_id = tbl.object_id),0.0) AS [DataSpaceUsed_KB],

ISNULL((select @PageSize * SUM(a.used_pages - CASE WHEN a.type <> 1 
THEN a.used_pages      WHEN p.index_id < 2 THEN a.data_pages ELSE 0 END)

FROM sys.indexes as i

JOIN sys.partitions as p ON p.object_id = i.object_id and p.index_id = i.index_id

JOIN sys.allocation_units as a ON a.container_id = p.partition_id

where i.object_id = tbl.object_id),0.0) AS [IndexSpaceUsed_KB]

FROM

sys.tables AS tbl

如果要查找每个表的空间,可以使用以下命令:

USE yourdbname
EXEC sp_MSforeachtable @command1="EXEC sp_spaceused '?'"
如需进一步阅读,请查看