sql server 数据库 管理员通常硬盘 空间 奋斗,不断努力清理表,撰写许多查询,发现该表 使用 的硬盘 空间 。 本文介绍了如何查询系统表的 空间 使用 情况,帮助 数据库 管理员识别正在 使用 最多的 空间 ,以便存档旧数据和清除非必要的数据表。 1。登录到s
sql server数据库管理员通常硬盘空间奋斗,不断努力清理“表”,撰写许多查询,发现该表使用的硬盘空间。
本文介绍了如何查询系统表的空间使用情况,帮助数据库管理员识别正在使用最多的空间,以便存档旧数据和清除非必要的数据表。
1。登录到sql server实例的[sql server 2005或sql server的2008]。
2。浏览到你想获得空间信息数据库。
3。复制并粘贴到您的查询窗口的代码,并执行它。
4。检查的结果,并查看选定的数据库内的表空间
declare @tablenm sysname, @cnt int, @topn intdeclare table_space cursor fast_forward for select name from sysobjects where xtype = 'u'select @cnt = 0, @topn = 0create table #tmpusage ( name sysname, rows int, reserved varchar(20), data varchar(20), index_size varchar(20), unused varchar(20) )open table_spacefetch next from table_space into @tablenmwhile @@fetch_status = 0 and @cnt <= @topnbegin insert into #tmpusage exec sp_spaceused @tablenm, 'true' if @topn 0 select @cnt = @cnt +1 fetch next from table_space into @tablenm endclose table_spacedeallocate table_spaceselect *from #tmpusage order by convert(int,left(reserved, len(reserved)- 3)) descif (select object_id('tempdb..#tmpusage') ) is not nulldrop table #tmpusage