zl程序教程

您现在的位置是:首页 >  数据库

当前栏目

Oracle 表结构、索引以及分区信息查询详解数据库

Oracle数据库索引 详解 查询 信息 结构 以及
2023-06-13 09:20:12 时间
select table_name from user_tables; --当前用户的表 select table_name from all_tables; --所有用户的表 select table_name from dba_tables; --包括系统表 --表字段信息 select * from all_tab_columns a where a.TABLE_NAME=T_X27_USER; --表注释信息 select * from user_tab_comments a where a.table_name=T_X27_USER; --表字段注释信息 select * from user_col_comments a where a.table_name=T_X27_USER; --表分区信息 --1,分区表信息 -- (1)显示数据库所有分区表的信息 select * from DBA_PART_TABLES a where a.owner=upper() and a.table_name=upper(); -- (2)显示当前用户可访问的所有分区表信息 select * from ALL_PART_TABLES a where a.owner=upper() and a.table_name=upper(); -- (3)显示当前用户所有分区表的信息 select * from USER_PART_TABLES a where a.table_name=upper(); --2,分区表的分区列信息 -- (1)显示当前用户所有分区表的分区列信息 select * from USER_PART_KEY_COLUMNS a where a.name=upper() and a.object_type=TABLE; -- (2)显示当前用户可访问的所有分区表的分区列信息 select * from ALL_PART_KEY_COLUMNS a where a.owner=upper(etl) and a.name=upper() and a.object_type=TABLE; --(3)显示分区列 显示数据库所有分区表的分区列信息 select * from DBA_PART_KEY_COLUMNS a where a.owner=upper(etl) and a.name=upper() and a.object_type=TABLE; -- 3,分区表的名字、归属表空间以及表的详细分区情况 select * from user_tab_partitions a where a.table_name=upper(); -- 4,查看组合表的子分区信息以及子分区列信息情况 -- (1)显示当前用户所有组合分区表的子分区信息 select * from USER_TAB_SUBPARTITIONS; -- (2)显示当前用户可访问的所有组合分区表的子分区信息 select * from ALL_TAB_SUBPARTITIONS; -- (3)显示当前用户可访问的所有组合分区表的子分区信息 select * from ALL_TAB_SUBPARTITIONS ; -- (4)显示当前用户所有分区表的子分区列信息 select * from USER_SUBPART_KEY_COLUMNS; -- (5)显示当前用户可访问的所有分区表的子分区列信息 select * from ALL_SUBPART_KEY_COLUMNS; -- (6)显示子分区列 显示数据库所有分区表的子分区列信息 select * from DBA_SUBPART_KEY_COLUMNS; --表包含的索引 select * from user_indexes where table_name=upper(T_X27_USER); --索引的具体信息:根据索引名查看索引包含的字段 select * from user_ind_columns where index_name = UK_T_X27_USER_USERID; --表的唯一约束条件 select * from user_constraints where constraint_type=U and owner=ETL and table_name=T_X27_USER; --表外键 select * from user_constraints where constraint_type=R and owner=ETL and table_name=T_X27_USER; --表外键以及约束条件字段组成信息 select * from user_cons_columns where owner=ETL and table_name=T_X27_USER;

 示例(oracle查看表结构信息):

select a.owner 所属用户, 

a.table_name 表名, 

a.column_name 字段名, 

a.data_type 字段类型, 

a.字段长度, 

a.字段精度, 

a.是否为空, 

a.创建日期, 

a.最后修改日期, 

case when a.owner=d.owner and a.table_name=d.table_name and a.column_name=d.column_name then 主键 else  end 是否主键 

from 

(select a.owner,a.table_name,b.column_name,b.data_type,case when b.data_precision is null then b.data_length else data_precision end 字段长度,data_scale 字段精度, 

decode(nullable,Y,√,N,×) 是否为空,c.created 创建日期,c.last_ddl_time 最后修改日期 

from all_tables a,all_tab_columns b,all_objects c 

where a.table_name=b.table_name and a.owner=b.owner 

and a.owner=c.owner 

and a.table_name=c.object_name 

and a.owner=SCOTT --这个是查某个用户,你到时候把用户名换一下就好,一定大写 

and c.object_type=TABLE) a 

left join 

(select a.owner,a.table_name,a.column_name,a.constraint_name from user_cons_columns a, user_constraints b 

where a.constraint_name = b.constraint_name and b.constraint_type = P) d 

on a.owner=d.owner and a.table_name=d.table_name and a.column_name=d.column_name 

order by a.owner,a.table_name;

 

原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/4984.html

oracle