具體
查詢表占用空間的主要語句為 exec sp_spaceused @temp;
微軟官方解釋:
--判斷臨時表是否存在,存在則刪除重建
if exists ( select 1
from tempdb..sysobjects
where id = object_id('tempdb..#tabname')
and xtype = 'u' )
drop table #tabname;
gocreate table #tabname
(tabname varchar(100)
,rowsnum varchar(100)
,reserved varchar(100)
,data varchar(100)
,index_size varchar(100)
,unused_size varchar(100)
);declare @name varchar(100);
declare @schemas varchar(100);
declare @temp varchar(100);
declare cur cursor
for select a.name
,s.name
from sys.objects a
,sys.schemas s
where a.type = 'u'
and a.schema_id = s.schema_id
order by a.name;
open cur;
fetch next from cur into @name , @schemas;
while @@fetch_status = 0
begin
set @temp = @schemas + '.[' + @name + ']';
insert into #tabname
exec sp_spaceused @temp;
print @temp;
fetch next from cur into @name , @schemas;
end;
close cur;
deallocate cur;
select tabname as '表名'
,rowsnum as '表資料行數'
,reserved as '保留大小'
,data as '資料大小'
,index_size as '索引大小'
,unused_size as '未使用大小'
from #tabname
order by cast(isnull(rowsnum , 0) as int) desc;
SQL Server資料庫查詢
開啟我們的sql server資料庫,找到要查詢的資料庫表,右鍵單擊然後選擇新建查詢,select 選擇我們要查詢的表sys academe學院表 聯合 sys class.classname班級表的班級名稱和sys grade.gradename年級表的年級編號來查詢出資料。下面是查詢的 sele...
SQL Server 跨資料庫查詢
語句 select from 資料庫a.dbo.表a a,資料庫b.dbo.表b b where a.field b.field dbo 可以省略 如 select from 資料庫a.表a a,資料庫b.表b b where a.field b.field sqlserver資料庫 這句是對映乙個...
查詢SQL SERVER 資料庫版本
select substring cast serverproperty productversion as nvarchar 128 1,charindex cast serverproperty productversion as nvarchar 128 1 1 8 對應 sql server...