如何查找哪些表引用了 Oracle SQL Developer 中的给定表?
在 Oracle SQL Developer 中,如果我正在查看以下信息:一个表,我可以查看约束,这让我可以看到外键(以及该表引用了哪些表),并且我可以查看依赖项以查看哪些包等引用了该表。 但我不确定如何找到哪些表引用了该表。
例如,假设我正在查看 emp
表。 还有另一个表emp_dept
,它捕获哪些员工在哪些部门工作,该表通过emp_id
(emp_id
)的主键引用emp
表。 >emp 表。 有没有办法(通过程序中的某些 UI 元素,而不是通过 SQL)找到 emp_dept
表引用 emp
表,而无需我知道 < code>emp_dept 表存在吗?
In Oracle SQL Developer, if I'm viewing the information on a table, I can view the constraints, which let me see the foreign keys (and thus which tables are referenced by this table), and I can view the dependencies to see what packages and such reference the table. But I'm not sure how to find which tables reference the table.
For example, say I'm looking at the emp
table. There is another table emp_dept
which captures which employees work in which departments, which references the emp
table through emp_id
, the primary key of the emp
table. Is there a way (through some UI element in the program, not through SQL) to find that the emp_dept
table references the emp
table, without me having to know that the emp_dept
table exists?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(12)
像这样的事情怎么样:
How about something like this:
仅将
table_name
替换为您的主表名称(在 OP 问题的情况下,将是emp
)Only Replace
table_name
with your primary table name (in the case of OP Question, that would beemp
)要添加到 sql Developer 插件的上述答案中,使用下面的 xml 将有助于获取与外键关联的列。
To add to the above answer for sql developer plugin, using the below xml will help in getting the column associated with the foreign key.
我喜欢使用直接的 SQL 查询来完成此操作,而不是使用 SQL Developer 应用程序。
这就是我刚刚做的。 最好通读本文并了解发生了什么,这样您就可以调整它以满足您的需求......
I like to do this with a straight SQL query, rather than messing about with the SQL Developer application.
Here's how I just did it. Best to read through this and understand what's going on, so you can tweak it to fit your needs...
替换下面的 MY_OWNER_NAME 和 MY_TABLE_NAME,然后您就可以RECURSIVELY了:
Replace MY_OWNER_NAME and MY_TABLE_NAME below and you are ready to go RECURSIVELY:
不可以。Oracle SQL Developer 没有提供这样的选项。
您必须手动执行查询或使用其他工具(例如 PLSQL Developer 有这样的选项) 。 以下 SQL 是 PLSQL Developer 使用的 SQL:
其中
r_owner
是架构,r_table_name
是您要查找引用的表。 名称区分大小写,请小心,因为在 Oracle SQL Developer 的报告选项卡上有一个选项“所有表/依赖项”,该选项来自 ALL_DEPENDENCIES 指“当前用户可访问的过程、包、函数、包体和触发器之间的依赖关系,包括依赖于在没有任何数据库链接的情况下创建的视图。”。 那么,这份报告对你的问题没有任何价值。
No. There is no such option available from Oracle SQL Developer.
You have to execute a query by hand or use other tool (For instance PLSQL Developer has such option). The following SQL is that one used by PLSQL Developer:
Where
r_owner
is the schema, andr_table_name
is the table for which you are looking for references. The names are case sensitiveBe careful because on the reports tab of Oracle SQL Developer there is the option "All tables / Dependencies" this is from ALL_DEPENDENCIES which refers to "dependencies between procedures, packages, functions, package bodies, and triggers accessible to the current user, including dependencies on views created without any database links.". Then, this report have no value for your question.
要将其作为扩展添加到 SQL Developer 中,请执行以下操作:
将扩展添加到 SQL Developer:
导航到任何表,您现在应该会在旁边看到一个附加选项卡SQL one,标记为 FK References,显示新的 FK 信息。
参考
To add this to SQL Developer as an extension do the following:
Add the extension to SQL Developer:
Navigate to any table and you should now see an additional tab next to SQL one, labelled FK References, which displays the new FK information.
Reference
在下面的查询中将 [Your TABLE] 替换为 emp
Replace [Your TABLE] with emp in the query below
您可以从
ALL_CONSTRAINTS
视图中查询:You may be able to query this from the
ALL_CONSTRAINTS
view:SQL Developer 4.1 于 2015 年 5 月发布,添加了一个“模型”选项卡,该选项卡显示以实体关系图格式引用表的表外键。
SQL Developer 4.1, released in May of 2015, added a Model tab which shows table foreign keys which refer to your table in an Entity Relationship Diagram format.
该产品已存在多年 - 尽管 2011 年尚未出现在产品中。
但是,只需单击“型号”页面即可。
确保您使用的版本至少为 4.0(2013 年发布)才能访问此功能。
This has been in the product for years - although it wasn't in the product in 2011.
But, simply click on the Model page.
Make sure you are on at least version 4.0 (released in 2013) to access this feature.