微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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,255) - data */ update #spt_space
set indexp = (select sum(used)
from sysindexes
where indid in (0,255)
and id = @id) - data
where objid = @id /* unused: sum(reserved) - sum(used) where indid in (0,255) */
update #spt_space
set unused = reserved - (
select sum(used)
from sysindexes
where indid in (0,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.,
IndexSizeKB = ltrim(str(indexp * d.low / 1024.,
UnusedKB = ltrim(str(unused * d.low / 1024.,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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


SELECT a.*,b.dp_name,c.pa_name,fm_name=(CASE WHEN a.fm_no=&#39;LJCG001H&#39; THEN dbo.ELTPNAME(a.fw_nu) ELSE d.fm_name END),e.fw_state_nm,f.fw_rmk_nm
if not exists(select name from syscolumns where name=&#39;tod_no&#39; and id=object_id(&#39;iebo09d12&#39;)) alter table iebo09d12 add tod_no varchar(
select a.*,pano=a.pa_no,b.pa_name,f.dp_name,e.fw_state_nm,g.fa_name from LJSS007H a (nolock) Left join LJPA002H b (nolock) On a.pa_no =b.pa_no Left jo
要在 SQL Server 2019 中设置定时自动重启,可以使用 Windows 任务计划程序。下面是详细的步骤: 步骤一:创建批处理文件 打开记事本。 输入以下内容: net stop &quot;SQL Server (MSSQLSERVER)&quot; net start &quot;SQ
您收到的错误消息表明数据库 &#39;EastRiver&#39; 的事务日志已满,导致数据库操作失败。要解决这个问题,可以按照以下步骤操作: 1. 备份事务日志首先,备份事务日志以释放空间: BACKUP LOG [EastRiver] TO DISK = N&#39;C:\Backup\East
首先我需要查询出需要使用SQL Server Profiler跟踪的数据库标识ID,若不知道怎么查询数据库的标识ID, 打开SQL Server management studio,点击工具。选择SQL Server Profiler。 登录,登录成功后,如果有个默认弹窗,先取消 新建追踪 命名
--最新的解决方法 --先创建用户帐户,不进行授权,然后通过下面的SQL语句将该用户帐户关联至对应的数据库用户。优点是避免了重新授权的操作。 USE tempdbEXEC sp_change_users_login &#39;Update_One&#39;, &#39;iemis&#39;, &#3
命令: ALTER TABLE 表名 add 列名 数据类型 default 默认值 not null 例如: ALTER TABLE LJEL005H add el_req int default 15 not null
declare @i int set @i=340 while @i&lt;415 begin set @i=@iʱ insert into LJWK007H select &#39;2024&#39;,&#39;28&#39;,&#39;9110&#39;,&#39;3PTSD621000000