国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費(fèi)電子書(shū)等14項(xiàng)超值服

開(kāi)通VIP
SQL Server 2005 查看數(shù)據(jù)庫(kù)表的大小 按照表大小排列
(1)Question:尼瑪一個(gè)數(shù)據(jù)庫(kù),動(dòng)輒幾十個(gè)G,傷不起啊,怎樣才能知道當(dāng)前數(shù)據(jù)庫(kù)里面各個(gè)表的大小呢?以便將部分較大的數(shù)據(jù)庫(kù)表中不容易被頻繁訪問(wèn)的數(shù)據(jù)歸檔到歷史表中,例如每天將一個(gè)自然年以前的數(shù)據(jù)放入歷史表中。
(2)Key:網(wǎng)上搜了一圈,關(guān)鍵字sp_spaceused (參見(jiàn):http://msdn.microsoft.com/zh-cn/library/ms188776.aspx)
(3)Sample:同時(shí)找到了一個(gè)示例(參見(jiàn):http://www.linuxso.com/linuxxitongguanli/519.html 推薦: SQL Server 2005 查看數(shù)據(jù)庫(kù)表的大小 按照表大小排列),下面就將這個(gè)示例的代碼原樣抄寫(xiě)下來(lái),供大家分享啦!對(duì)了,我在2005上驗(yàn)證過(guò),代碼沒(méi)有什么大問(wèn)題。
(4)Code:
(4.1)將表大小占用情況存放到新創(chuàng)建的 tablespaceinfo表中
SQL code
if not exists (select from dbo.sysobjects where id = object_id(N'[dbo].[tablespaceinfo]'and OBJECTPROPERTY(id, N'IsUserTable') = 1)
create table tablespaceinfo --創(chuàng)建結(jié)果存儲(chǔ)表
(nameinfo varchar(50) , 
rowsinfo int , reserved varchar(20) , 
datainfo varchar(20) , 
index_size varchar(20) , 
unused varchar(20) )
 
delete from tablespaceinfo --清空數(shù)據(jù)表
 
declare @tablename varchar(255) --表名稱
 
declare @cmdsql varchar(500)
 
DECLARE Info_cursor CURSOR FOR 
select o.name 
from dbo.sysobjects o where OBJECTPROPERTY(o.id, N'IsTable') = 1 
and o.name not like N'#%%' order by o.name
 
OPEN Info_cursor
 
FETCH NEXT FROM Info_cursor 
INTO @tablename 
 
WHILE @@FETCH_STATUS = 0
BEGIN
 
if exists (select from dbo.sysobjects where id = object_id(@tablename) and OBJECTPROPERTY(id, N'IsUserTable') = 1)
execute sp_executesql 
N'insert into tablespaceinfo exec sp_spaceused @tbname',
N'@tbname varchar(255)',
@tbname = @tablename
 
FETCH NEXT FROM Info_cursor 
INTO @tablename 
END
 
CLOSE Info_cursor
DEALLOCATE Info_cursor
GO


(4.2)查看當(dāng)前數(shù)據(jù)庫(kù)大小情況
SQL code
--itlearner注:顯示數(shù)據(jù)庫(kù)信息
sp_spaceused @updateusage = 'TRUE' 

(4.3)查看存放了當(dāng)前數(shù)據(jù)庫(kù)各個(gè)表大小的tablespaceinfo表中記錄
SQL code
--itlearner注:顯示表信息
select 
from tablespaceinfo 
order by cast(left(ltrim(rtrim(reserved)) , len(ltrim(rtrim(reserved)))-2) as intdesc 

更多 0

sp_spaceused的結(jié)果有時(shí)是不準(zhǔn)確的, 要加updateusage選項(xiàng)才行.
SQL code
1
sp_spaceused @objname=N'[表名]',@updateusage=true

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)
打開(kāi)APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
分享一個(gè)SQLSERVER腳本(計(jì)算數(shù)據(jù)庫(kù)中各個(gè)表的數(shù)據(jù)量和每行記錄所占用空間)
OracleSQL語(yǔ)言
數(shù)據(jù)操作技巧: 禁用約束和觸發(fā)器
在sql server數(shù)據(jù)庫(kù)中快速刪除記錄,清空表
利用觸發(fā)器進(jìn)行數(shù)據(jù)實(shí)時(shí)傳輸?shù)脑O(shè)計(jì)與實(shí)
MySQL數(shù)據(jù)庫(kù)介紹
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服