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/SQLServer/201311/22406.html