sql查看所有表大小的方法
declare @id int
declare @type character(2)
declare @pages int
declare @dbname sysname
declare @dbsize dec(15,0)
declare @bytesperpage dec(15,0)
declare @pagesperMB dec(15,0)
create table #spt_space
(
[objid] int null,
[rows] int null,
[reserved] dec(15) null,
[data] dec(15) null,
[indexp] dec(15) null,
[unused] dec(15) null
)
set nocount on
-- Create a cursor to loop through the user tables
declare c_tables cursor for
select id from sysobjects where xtype = 'U'
open c_tables fetch next from c_tables into @id
while @@fetch_status = 0
begin
/* Code from sp_spaceused */
insert into #spt_space (objid, reserved)
select objid = @id, sum(reserved)
from sysindexes
where indid in (0, 1, 255) and id = @id
select @pages = sum(dpages)
from sysindexes
where indid < 2
and id = @id
select @pages = @pages + isnull(sum(used), 0)
from sysindexes
where indid = 255 and id = @id
update #spt_space set data = @pages
where objid = @id
/* index: sum(used) where indid in (0, 1, 255) - data */
update #spt_space
set indexp = (select sum(used)
from sysindexes
where indid in (0, 1, 255)
and id = @id) - data
where objid = @id
/* unused: sum(reserved) - sum(used) where indid in (0, 1, 255) */
update #spt_space
set unused = reserved - (
select sum(used)
from sysindexes
where indid in (0, 1, 255) and id = @id
)
where objid = @id
update #spt_space set [rows] = i.[rows]
from sysindexes i
where i.indid < 2 and i.id = @id and objid = @id
fetch next from c_tables into @id
end
select TableName = (select left(name,60) from sysobjects where id = objid),
[Rows] = convert(char(11), rows),
ReservedKB = ltrim(str(reserved * d.low / 1024.,15,0) + ' ' + 'KB'),
DataKB = ltrim(str(data * d.low / 1024.,15,0) + ' ' + 'KB'),
IndexSizeKB = ltrim(str(indexp * d.low / 1024.,15,0) + ' ' + 'KB'),
UnusedKB = ltrim(str(unused * d.low / 1024.,15,0) + ' ' + 'KB')
from #spt_space, master.dbo.spt_values d
where d.number = 1
and d.type = 'E'
order by reserved desc
drop table #spt_space
close c_tables
deallocate c_tables
相關(guān)文章
sql server 臨時(shí)表 查找并刪除的實(shí)現(xiàn)代碼
考慮使用表變量而不使用臨時(shí)表。當(dāng)需要在臨時(shí)表上顯式地創(chuàng)建索引時(shí),或多個(gè)存儲過程或函數(shù)需要使用表值時(shí),臨時(shí)表很有用。通常,表變量提供更有效的查詢處理。2008-12-12SQL實(shí)現(xiàn)模糊查詢的四種方法總結(jié)
本文主要介紹了SQL實(shí)現(xiàn)模糊查詢的四種方法總結(jié),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-07-07沒有SQL Server數(shù)據(jù)庫時(shí)如何打開.MDF文件
本文主要介紹了在安裝有Visual Studio 2005或以上的版本的前提下,沒有安裝SQL Server數(shù)據(jù)庫也可以打開.MDF數(shù)據(jù)庫文件的方法,需要的朋友可以參考下2015-08-08SQLServer 數(shù)據(jù)導(dǎo)入導(dǎo)出的幾種方法小結(jié)
在涉及到SQL Server編程或是管理時(shí)一定會用到數(shù)據(jù)的導(dǎo)入與導(dǎo)出, 導(dǎo)入導(dǎo)出的方法有多種,結(jié)合我在做項(xiàng)目時(shí)的經(jīng)歷做一下匯總2010-06-06centos7部署SqlServer2019的實(shí)現(xiàn)步驟
最近工作需要,需要在服務(wù)器上部署一個(gè)sql server 數(shù)據(jù)庫,本文主要介紹了centos7部署SqlServer2019的實(shí)現(xiàn)步驟,具有一定的參考價(jià)值,感興趣的可以了解一下2024-01-01SQL Server統(tǒng)計(jì)信息更新時(shí)采樣百分比對數(shù)據(jù)預(yù)估準(zhǔn)確性的影響詳解
這篇文章主要給大家介紹了關(guān)于SQL Server統(tǒng)計(jì)信息更新時(shí)采樣百分比對數(shù)據(jù)預(yù)估準(zhǔn)確性影響的相關(guān)資料,文中通過圖文介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2018-09-09