1 --獲取所有用戶表的空間占用情況
2 create procedure sp_get_table_space_info
3 as
4 begin
5 if not exists(select * from sysobjects where xtype='U' and name='TableSpaceInfo')
6 create table TableSpaceInfo(
7 name varchar(255),
8 rows bigint,
9 reserved varchar(20),
10 data varchar(20),
11 index_size varchar(20),
12 unused varchar(20)
13 )
14 delete from TableSpaceInfo
15 exec sp_MSforeachtable "insert into TableSpaceInfo exec sp_spaceused '?'"
16 end
17 go
調用的時候執行一次,然後直接查詢 TableSpaceInfo 表就可以了!
獲取數據庫的大小執行 exec sp_spaceused 就可以了