是否有查询在Oracle_sqldeveloper中查找表结构

时间:2014-07-31 09:17:12

标签: oracle-sqldeveloper

您好我是oracle sql开发人员的新手,请您解答如何知道数据库的表结构和关系。

3 个答案:

答案 0 :(得分:3)

1)输入您的表名。 2)右键单击表名称&单击“打开声明”。

答案 1 :(得分:2)

你可以尝试

DESC <table_name>

答案 2 :(得分:0)

试试这个:

select table_name, column_name, data_type 
  from all_tab_columns
 where table_name = <TABLE_NAME_HERE>
   and owner = '<YOUR_USER_HERE_IN_CAPITAL_LETTERS>'

如果您对表有评论,那么要获得列的评论:

select tc.table_name, tc.column_name, tc.data_type, cc.comments
  from all_coll_comments cc, all_tab_columns tc
 where tc.table_name = <TABLE_NAME_HERE>
   and tc.owner = <OWNER_OF_TABLE_HERE>
   and tc.table_name = cc.table_name
   and tc.column_name = cc.column_name
   and tc.owner = cc.owner

如果您在表的所有者下登录,则可以写下:

select table_name, column_name, data_type 
  from user_tab_columns
 where table_name = <TABLE_NAME_HERE>

或获取包含评论的列

select tc.table_name, tc.column_name, tc.data_type, cc.comments
  from user_coll_comments cc, user_tab_columns tc
 where tc.table_name = '<TABLE_NAME_HERE>'
   and tc.owner = '<YOUR_USER_HERE_IN_CAPITAL_LETTERS>'
   and tc.table_name = cc.table_name
   and tc.column_name = cc.column_name

要获取表之间的关系,请使用此查询:

select uc1.table_name
     , uc1.constraint_name
     , cc1.column_name
     , uc2.table_name r_table_name
     , uc2.constraint_name r_constraint_name
     , cc2.column_name r_column_name
  from all_constraints uc1
     , all_constraints uc2
     , all_cons_columns cc1
     , all_cons_columns cc2
 where 1 = 1
   and uc2.constraint_type = 'R'
   and uc1.constraint_name = uc2.r_constraint_name
   and cc1.table_name = uc1.table_name
   and cc1.constraint_name = uc1.constraint_name
   and cc2.table_name = uc1.table_name
   and cc2.constraint_name = uc1.constraint_name
   and uc1.owner = '<YOUR_USER_HERE_IN_CAPITAL_LETTERS>'
   and uc2.owner = uc1.owner
   and cc1.owner = uc1.owner
   and cc2.owner = uc1.owner
 order by 1
/

带有“R_”前缀的列表示它们是外来数据(它们代表外键)。正如您所看到的,我使用带有“ALL_”前缀的表,使用带有“USER_”前缀的类似表,摆脱“OWNER”部分。 要了解有关oracle数据字典的更多信息,请阅读this