sql server 2008 mdf文件太大了80多G 实际表的空间很小
sql server 2008 mdf文件太大了80多G 实际表的空间很小 已完成收缩。
select object_name(id) tablename,8*reserved/1024 reserved,rtrim(8*dpages/1024)+'Mb' used,8*(reserved-dpages)/1024 unused,8*dpages/1024-rows/1024*minlen/1024 free, rows,* from sysindexes where indid=1 order by reserved desc 查看每个表使用空间很小,有数据的表已全部被删除了!
索引检查也没有问题,还有什么办法来检查?
谢谢各位。
------解决方案--------------------
给你一个查看数据库表中容量大小的SQL代码可以看到数据库中的表有多少记录,占多少空间以及索引的大小,以及未使用的空间:
==============查看数据库表的容量大小========start================================?============
Create Table #TableSpaceInfo --创建结果存储表
(
NameInfo NVarchar(50) ,
RowsInfo int ,
Reserved NVarchar(20) ,
DataInfo NVarchar(20) ,
Index_Size NVarchar(20) ,
Unused NVarchar(20)
)
Declare @TableName NVarchar(255) --表名称
Declare @CmdSql NVarchar(1000)
Declare Info_Cursor Cursor For
Select o.Name
From dbo.sysobjects o
Where objectProperty(o.ID, N'IsTable') = 1 and o.Name not like N'#%%' Order By o.Name
Open Info_Cursor
Fetch Next From Info_Cursor
Into @TableName
While @@FETCH_STATUS = 0
Begin
If exists (Select * From dbo.sysobjects Where ID=object_ID(@tablename) and objectProperty(ID, N'IsUserTable') = 1)
Execute sp_executesql N'Insert Into #TableSpaceInfo Exec sp_Spaceused @TBName', N'@TBName NVarchar(255)', @TBName = @TableName
Fetch Next From Info_Cursor
Into @TableName
End
Close Info_Cursor
Deallocate Info_cursor
GO
--itlearner注:显示数据库信息
sp_spaceused @UpdateUsage = 'TRUE'
--itlearner注:显示表信息
Select *
From #TableSpaceInfo
Order By cast(left(lTrim(rTrim(Reserved)) , len(lTrim(rTrim(Reserved)))-2) As Int) Desc
Drop Table #TableSpaceInfo
================查看数据库表的容量大小=====end========================?==========================
转载于:https://blog.51cto.com/10264855/1853980