Oracle之获取SQL对应表的信息

本文提供了针对Oracle数据库中两个特定表T1和T2的详细诊断步骤,包括表的大小、触发器情况、表结构信息及分区详情等,有助于数据库管理员深入了解表的状态,并据此进行优化。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >



SET LINESIZE 666
set pagesize 5000
column index_name format a30
column table_name format a26
column num_rows format 999999999
column index_type format a24
column num_rows format 999999999
column status format a8
column clustering_factor format 999999999
column degree format a10
column blevel format 9
column distinct_keys format 9999999999
column leaf_blocks format   9999999
column last_analyzed    format a10
column column_name format a25
column column_position format 9
column temporary format a2
column partitioned format a5
column partitioning_type format a7
column partition_count format 999




--1.查看表大小情况


--记录的大小
select count(*) from T1;
select count(*) from T2; 


--物理的大小
select segment_name,sum(bytes)/1024/1024 
from  user_segments 
where segment_name in ('T1',
                       'T2') 
group by segment_name;




--2.查看表是否有触发器


select OWNER, TRIGGER_NAME, TABLE_NAME, STATUS
  from dba_triggers
 where table_name in  ('T1',
                       'T2');  
 
 
---3.查看表结构情况




--查看表信息
/*
   通过temporary,partitioned,iot_type三个字段可知表的类型是否是全局临时表、是否是分区表、是否是索引组织表
   通过degree字段可得是否有被设置为并行度的属性(值大于1)
   通过观察last_analyzed字段值可知是否有正常收集,看有无值,或者是看时间是否很久以前的。
*/
select  t.table_name,
        t.num_rows,
        t.blocks,
        t.degree,
        t.last_analyzed,
        t.temporary,
        t.partitioned,
        t.iot_type,
        t.pct_free,
        t.tablespace_name
from user_tables t
where table_name in ('T1',
                     'T2')   ;                   
                 
                      
--查看分区表相关信息(user_part_tables记录分区的表的信息,user_tab_partitions记录表的分区的信息)


--了解这些表的分区是什么类型的,有多少个分区
select t.table_name,                                             
       t.partitioning_type,                                            
       t.partition_count                                               
  from user_part_tables t                                               
 where table_name in ('T1',
                      'T2') ;
         
                               
--了解这些表以什么列作为分区                                
select name,object_type, column_name                                                                                                                   
  from user_part_key_columns                                                                                 
 where name in ('T1',
                'T2') ;                 


         
--了解这些表的分区范围是多少
SELECT table_name,partition_name, high_value, tablespace_name
  FROM user_tab_partitions t
 where table_name in ('T1',
                      'T2') 
 order by table_name,t.partition_position;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值