如何 select 最大前 10 (n) 行的大小?
how to select max top 10 (n) rows with there size?
我已经有了下面的查询,它获取了 tables 的大小。但是,我只对获得最大尺寸 table 的前 10 名感兴趣。
怎么做?
select convert(varchar(30),o.name) AS table_name,
row_count(db_id(), o.id) AS row_count,
data_pages(db_id(), o.id, 0) AS pages,
data_pages(db_id(), o.id, 0) * (@@maxpagesize/1024) AS kbs
from sysobjects o
where type = 'U'
order by table_name
正在搜索类似的:select top 10 max(datapages) from sysobjects
编辑:
现在我还必须获取索引的大小,将 sysindexes 添加到查询中就足够了,或者应该添加另一个系统 table,例如 syscomments ?
这样写就是给了我 top table name:
select top 10 convert(varchar(30),o.name) AS table_name,
row_count(db_id(), o.id) AS row_count,
data_pages(db_id(), o.id, 0) AS pages,
data_pages(db_id(), o.id, 0) * (@@maxpagesize/1024) AS kbs
from sysobjects o
where type = 'U'
order by table_name , kbs
这是抛出错误
select top 10 data_pages(db_id(), o.id, 0) * (@@maxpagesize/1024) AS kbs ,
convert(varchar(30),o.name) AS table_name,
row_count(db_id(), o.id) AS row_count,
data_pages(db_id(), o.id, 0) AS pages
from sysobjects o
where type = 'U'
order by kbs , table_name
此查询适用于我的 ASE 16.0 系统:
select top 10 convert(varchar(30),o.name) AS table_name,
row_count(db_id(), o.id) AS row_count,
data_pages(db_id(), o.id, 0) AS pages,
data_pages(db_id(), o.id, 0) * (@@maxpagesize/1024) AS kbs
from sysobjects o
where type = 'U'
order by kbs DESC, table_name ASC
我已经有了下面的查询,它获取了 tables 的大小。但是,我只对获得最大尺寸 table 的前 10 名感兴趣。
怎么做?
select convert(varchar(30),o.name) AS table_name,
row_count(db_id(), o.id) AS row_count,
data_pages(db_id(), o.id, 0) AS pages,
data_pages(db_id(), o.id, 0) * (@@maxpagesize/1024) AS kbs
from sysobjects o
where type = 'U'
order by table_name
正在搜索类似的:select top 10 max(datapages) from sysobjects
编辑:
现在我还必须获取索引的大小,将 sysindexes 添加到查询中就足够了,或者应该添加另一个系统 table,例如 syscomments ?
这样写就是给了我 top table name:
select top 10 convert(varchar(30),o.name) AS table_name,
row_count(db_id(), o.id) AS row_count,
data_pages(db_id(), o.id, 0) AS pages,
data_pages(db_id(), o.id, 0) * (@@maxpagesize/1024) AS kbs
from sysobjects o
where type = 'U'
order by table_name , kbs
这是抛出错误
select top 10 data_pages(db_id(), o.id, 0) * (@@maxpagesize/1024) AS kbs ,
convert(varchar(30),o.name) AS table_name,
row_count(db_id(), o.id) AS row_count,
data_pages(db_id(), o.id, 0) AS pages
from sysobjects o
where type = 'U'
order by kbs , table_name
此查询适用于我的 ASE 16.0 系统:
select top 10 convert(varchar(30),o.name) AS table_name,
row_count(db_id(), o.id) AS row_count,
data_pages(db_id(), o.id, 0) AS pages,
data_pages(db_id(), o.id, 0) * (@@maxpagesize/1024) AS kbs
from sysobjects o
where type = 'U'
order by kbs DESC, table_name ASC