close
SQL server取得所有table資料筆數的方法
以下指令可以查詢SQL server資料庫所有table的資料筆數 (由大到小排列)。可以很快知道資料筆數大的table,並做進一步管理。
select o.name, i.rows
from sysobjects o inner join sysindexes i on o.id = i.id
where i.indid = 1
order by i.rows desc
如下圖
其他資料庫的Tables 資料筆數取法
Sybase :
select O.name,rowcnt(I.doampg) RecCnt from sysobjects O,sysindexes I
where I.id=O.id and I.indid=1 and O.type='U'
Oracle :
A. Compute statistics collection :
1. use table characterics :
create table with 'monitoring' option. and using PL/SQL
"analyze table [TableName] compute statistics;
2. use dbms_stats packages :
EXECUTE dbms_stats.gather_schema_stats (user);
EXECUTE dbms_stats.gather_table_stats (user,'[TableName]');
B. Get Number of rows from all_tables view.
Sybase :
select O.name,rowcnt(I.doampg) RecCnt from sysobjects O,sysindexes I
where I.id=O.id and I.indid=1 and O.type='U'
Oracle :
A. Compute statistics collection :
1. use table characterics :
create table with 'monitoring' option. and using PL/SQL
"analyze table [TableName] compute statistics;
2. use dbms_stats packages :
EXECUTE dbms_stats.gather_schema_stats (user);
EXECUTE dbms_stats.gather_table_stats (user,'[TableName]');
B. Get Number of rows from all_tables view.
select table_name,num_rows from all_tables where owner=user;
另一個好用的store procedure是sp_spaceused,
這個指令可以查詢某個table目前的資料筆數和資料所佔的硬碟空間,指令如下:
exec sp_spaceused
全站熱搜