標籤:des ar for sp on c size sql r
--檢查已標記為需要刪除的暫存資料表
select * from
T_BAS_TEMPORARYTABLENAME;
--所有系統建立的暫存資料表及視圖
SELECT * FROM sys.tables
WHERE name LIKE ‘TMP%‘
-- 查看系統所有表佔用的空間情況
create table tmpspace
(Fname varchar(50),
Frows int,
Freserved varchar(50),
Fdata
varchar(50),
Findex_size varchar(50),
Funused
varchar(50));
insert into tmpspace
(Fname,Frows,Freserved, Fdata,Findex_size,Funused)
exec sp_msforeachTable
@Command1="sp_spaceused ‘?‘"
select * from tmpspace where Fname like
‘TMP%‘ order by Fdata desc
--暫存資料表佔用的總大小(M)
select
SUM(CONVERT(DECIMAL,replace(fdata,‘KB‘,‘‘)))/1024 M from tmpspace where Fname
like ‘TMP%‘;
--drop table tmpspace;
--刪除所有已經標記為需要刪除的暫存資料表
declare
@sql as varchar(max)
set @sql=‘‘
select @[email protected]+‘drop table ‘+name+‘;‘
from sys.tables u
join T_BAS_TEMPORARYTABLENAME v on u.name=v.FTABLENAME and
( v.FPROCESSTYPE=1 or
v.FCREATEDATE<GETDATE()-1);
exec(@sql);
delete u from
T_BAS_TEMPORARYTABLENAME u where
not exists(select 1 from sys.tables where
u.ftablename=name );
【S】SQL SERVER檢查暫存資料表佔用空間情況