Oracle 表结构、索引以及分区信息查询
1/* 获取表:*/ 2select table_name from user_tables; --当前用户的表 3select table_name from all_tables; --所有用户的表 4select table_name from dba_tables; --包括系统表 5--表字段信息 6select * from all_tab_columns a where a.TABLE_NAME='T_X27_USER'; 7--表注释信息 8select * from user_tab_comments a where a.table_name='T_X27_USER'; 9--表字段注释信息 10select * from user_col_comments a where a.table_name='T_X27_USER'; 11--表分区信息 12--1,分区表信息 13-- (1)显示数据库所有分区表的信息 14select * from DBA_PART_TABLES a where a.owner=upper('') and a.table_name=upper(''); 15-- (2)显示当前用户可访问的所有分区表信息 16select * from ALL_PART_TABLES a where a.owner=upper('') and a.table_name=upper(''); 17-- (3)显示当前用户所有分区表的信息 18select * from USER_PART_TABLES a where a.table_name=upper(''); 19--2,分区表的分区列信息 20-- (1)显示当前用户所有分区表的分区列信息 21select * from USER_PART_KEY_COLUMNS a where a.name=upper('') and a.object_type='TABLE'; 22-- (2)显示当前用户可访问的所有分区表的分区列信息 23select * from ALL_PART_KEY_COLUMNS a where a.owner=upper('etl') and a.name=upper('') and a.object_type='TABLE'; 24--(3)显示分区列 显示数据库所有分区表的分区列信息 25select * from DBA_PART_KEY_COLUMNS a where a.owner=upper('etl') and a.name=upper('') and a.object_type='TABLE'; 26-- 3,分区表的名字、归属表空间以及表的详细分区情况 27select * from user_tab_partitions a where a.table_name=upper(''); 28-- 4,查看组合表的子分区信息以及子分区列信息情况 29-- (1)显示当前用户所有组合分区表的子分区信息 30select * from USER_TAB_SUBPARTITIONS; 31-- (2)显示当前用户可访问的所有组合分区表的子分区信息 32select * from ALL_TAB_SUBPARTITIONS; 33-- (3)显示当前用户可访问的所有组合分区表的子分区信息 34select * from ALL_TAB_SUBPARTITIONS ; 35-- (4)显示当前用户所有分区表的子分区列信息 36select * from USER_SUBPART_KEY_COLUMNS; 37-- (5)显示当前用户可访问的所有分区表的子分区列信息 38select * from ALL_SUBPART_KEY_COLUMNS; 39-- (6)显示子分区列 显示数据库所有分区表的子分区列信息 40select * from DBA_SUBPART_KEY_COLUMNS; 41--表包含的索引 42select * from user_indexes where table_name=upper('T_X27_USER'); 43--索引的具体信息:根据索引名查看索引包含的字段 44select * from user_ind_columns where index_name = 'UK_T_X27_USER_USERID'; 45--表的唯一约束条件 46select * from user_constraints where constraint_type='U' and owner='ETL' and table_name='T_X27_USER'; 47--表外键 48select * from user_constraints where constraint_type='R' and owner='ETL' and table_name='T_X27_USER'; 49--表外键以及约束条件字段组成信息 50select * from user_cons_columns where owner='ETL' and table_name='T_X27_USER';
示例(oracle查看表结构信息):
1select a.owner 所属用户, 2a.table_name 表名, 3a.column_name 字段名, 4a.data_type 字段类型, 5a.字段长度, 6a.字段精度, 7a.是否为空, 8a.创建日期, 9a.最后修改日期, 10case when a.owner=d.owner and a.table_name=d.table_name and a.column_name=d.column_name then '主键' else '' end 是否主键 11from 12(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 字段精度, 13decode(nullable,'Y','√','N','×') 是否为空,c.created 创建日期,c.last_ddl_time 最后修改日期 14from all_tables a,all_tab_columns b,all_objects c 15where a.table_name=b.table_name and a.owner=b.owner 16and a.owner=c.owner 17and a.table_name=c.object_name 18and a.owner='SCOTT' --这个是查某个用户,你到时候把用户名换一下就好,一定大写 19and c.object_type='TABLE') a 20left join 21(select a.owner,a.table_name,a.column_name,a.constraint_name from user_cons_columns a, user_constraints b 22where a.constraint_name = b.constraint_name and b.constraint_type = 'P') d 23on a.owner=d.owner and a.table_name=d.table_name and a.column_name=d.column_name 24order by a.owner,a.table_name;