其實只要使用系統內置的存儲過程sp_spaceused就可以得到表的相關信息
如
以下是為了方便寫的一個存儲過程
CREATE PROCEDURE get_tableinfo AS
if not exists (select * from dbo
create table tablespaceinfo
(nameinfo varchar(
rowsinfo int
datainfo varchar(
index_size varchar(
unused varchar(
delete from tablespaceinfo
declare @tablename varchar(
declare @cmdsql varchar(
DECLARE Info_cursor CURSOR FOR
select o
from dbo
and o
OPEN Info_cursor
FETCH NEXT FROM Info_cursor
INTO @tablename
WHILE @@FETCH_STATUS =
BEGIN
if exists (select * from dbo
execute sp_executesql
N
N
@tbname = @tablename
FETCH NEXT FROM Info_cursor
INTO @tablename
END
CLOSE Info_cursor
DEALLOCATE Info_cursor
GO
執行存儲過程
exec get_tableinfo
查詢運行該存儲過程後得到的結果
select *
from tablespaceinfo
order by cast(left(ltrim(rtrim(reserved))
From:http://tw.wingwit.com/Article/program/MySQL/201311/29385.html