ORACLA 查看表信息 表结构

こ雲淡風輕ζ 提交于 2020-01-09 17:00:32

--查看某用户下的表
select * from all_tab_comments a where a.TABLE_TYPE='TABLE'
and a.OWNER ='用户' and a.COMMENTS is not null;

--查看表 字段名称 字段类型 字段长度 字段描述
select ta.COLUMN_NAME as 字段名称,ta.DATA_TYPE as 字段类型,
ta.DATA_LENGTH as 字段长度,tb.comments as 字段描述
from user_tab_columns ta,user_col_comments tb
where ta.table_name=tb.table_name and ta.COLUMN_NAME=tb.column_name
and ta.table_name = '表名称';

--查询所有用户的表、视图等
select * from all_tab_comments;

--查询当前用户的所有表、视图等
select * from user_tab_comments;

--查询所有用户的表的列名和注释
select * from all_col_comments;

--查询当前用户的表的列名和注释
select * from user_col_comments;

--查询所有用户的表的列的结构信息(没有备注)
select * from all_tab_columns;

--查询当前户的表的列的结构信息(没有备注)
select * from user_tab_columns;
--组合版
SELECT USER_TAB_COLS.COLUMN_NAME as 列名 ,
USER_TAB_COLS.DATA_TYPE as 数据类型,
USER_TAB_COLS.DATA_LENGTH as 长度,
USER_TAB_COLS.NULLABLE as 是否为空, case
when (SELECT col.column_name FROM user_constraints con, user_cons_columns col
where con.constraint_name = col.constraint_name and con.constraint_type='P'
and col.table_name = '表名' and col.column_name = USER_TAB_COLS.COLUMN_NAME) = USER_TAB_COLS.COLUMN_NAME THEN 'Y'
ELSE 'N' END as 是否主键, case when (select count(*) from user_constraints con,
user_cons_columns col, (select t2.table_name,t2.column_name,t1.r_constraint_name
from user_constraints t1,user_cons_columns t2 where t1.r_constraint_name=t2.constraint_name and t1.table_name='表名') r
where con.constraint_name=col.constraint_name and con.r_constraint_name=r.r_constraint_name and con.table_name='表名'
and col.column_name = USER_TAB_COLS.COLUMN_NAME) > 0 then 'Y' else 'N' END as 是否外键 ,
user_col_comments.comments as 备注 FROM USER_TAB_COLS inner join user_col_comments
on user_col_comments.TABLE_NAME = USER_TAB_COLS.TABLE_NAME and user_col_comments.COLUMN_NAME=USER_TAB_COLS.COLUMN_NAME
and USER_TAB_COLS.TABLE_NAME = '表名' ORDER BY USER_TAB_COLS.COLUMN_ID;

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!