如何查询某张表占用多少物理空间
数据库是SQL 2008 R2
刚开始数据库也就100M
但是用了不到2个月,
发现已经500M了
想每张表占用了多少?
请教如何查询?
[解决办法]
exec sp_MSforeachtable@command1="print '?' exec sp_MStablespace '?'"
[解决办法]
DECLARE @tablespaceinfo TABLE ( nameinfo varchar(50), rowsinfo int, reserved varchar(20), datainfo varchar(20), index_size varchar(20), unused varchar(20) ) DECLARE @tablename varchar(255); DECLARE Info_cursor CURSOR FOR SELECT [name] FROM sys.tables WHERE type='U'; OPEN Info_cursor FETCH NEXT FROM Info_cursor INTO @tablename WHILE @@FETCH_STATUS = 0 BEGIN insert into @tablespaceinfo exec sp_spaceused @tablename FETCH NEXT FROM Info_cursor INTO @tablename END CLOSE Info_cursor DEALLOCATE Info_cursor SELECT * FROM @tablespaceinfo ORDER BY Cast(Replace(reserved,'KB','') as INT) DESC
[解决办法]
压缩日志? 网上一大把
[解决办法]
http://www.cnblogs.com/downmoon/archive/2009/12/13/1623004.html
[解决办法]
MSSQL2008及以上:
exec sp_helpdb '数据库名' --查看指定数据库
exec sp_databases --查看全部数据库