MSSQL中查所有表資料大小

2021-05-28 17:54:40 字數 1107 閱讀 8946

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 *, convert(varchar, ((

cast(replace(reserved,'kb','') as int) +

cast(replace(datainfo,'kb','') as int) +

cast(replace(index_size,'kb','') as int) +

cast(replace(unused,'kb','') as int)

) / (1024 * 1024)

)) + ' g'

as totaldata

from @tablespaceinfo order by cast(replace(reserved,'kb','') as int) desc

列出MSSQL所有資料庫名 所有表名 所有欄位名

列出mssql所有資料庫名 所有表名 所有欄位名 1.獲取所有資料庫名 select name from master.sysdatabases order by name 2.獲取所有表名 select name from sysobjects where xtype u order by nam...

檢視所有表空間大小

1.檢視所有表空間大小 sql select tablespace name,sum bytes 1024 1024from dba data files 2 group by tablespace name 2.已經使用的表空間大小 sql select tablespace name,sum b...

MSSQL 獲取所有表及字段定義

select 表名 case when a.colorder 1 then d.name else end,表說明 case when a.colorder 1 then isnull f.value,else end,字段序號 a.colorder,欄位名 a.name,標識 case when ...