查看oracle关于主/外键约束的元数据
哪个表包含有关约束的详细信息(例如外键引用的表)?表 'all_cons_columns' 、 'all_constraints' 仅包含约束的名称,这不是很有帮助。 我目前正在使用 dbms_metadata.get_ddl() 但它不适用于所有数据库。
谢谢。
Which table contains detailed information(For example the table the foreign key is referring to) about the constraints? The tables 'all_cons_columns' , 'all_constraints' contains only the name of the constraints which isn't very helpful.
I am currently using dbms_metadata.get_ddl() but it doesn't work on all the databases.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
一切都在其中:ALL_CONSTRAINTS 中的 R_CONSTRAINT_NAME 列包含外键引用的 PK/UK 约束的名称。然后,您可以查找该约束以获取引用表的 TABLE_NAME。
查看 ALL_CONS_COLUMNS 时,外键中列的位置将与主/唯一键中列的位置匹配。
It is all in there: the column R_CONSTRAINT_NAME in ALL_CONSTRAINTS contains the name of the referenced PK/UK constraint for a foreign key. You can then look up that constraint to get the TABLE_NAME of the reference table.
When looking at ALL_CONS_COLUMNS, the POSITION of the column in the foreign key will match the POSITION of the column in the primary/unique key.
此语句列出表、约束名称和外键表名称:
This statement lists tables, constraint names, and foreign key table names:
为了检索外键并生成脚本来创建它们,您可以使用以下查询:
In order to retrieve the foreign key and generate a script to create these, you can use the following query:
看一下:对数据模型进行逆向工程。基于此,我做了 将 Oracle 数据库架构转储为文本的 Python 程序。有
PRIMARY_KEYS_INFO_SQL
和FOREIGN_KEYS_INFO_SQL
可以执行您感兴趣的操作。Have a look at: Reverse Engineering a Data Model. Based on this I did a Python program that dumps Oracle db schema to text. There is
PRIMARY_KEYS_INFO_SQL
andFOREIGN_KEYS_INFO_SQL
that do what you are interested in.使用 Oracle XE 示例数据库。我想识别架构/表上的主键和外键。 在
输出(格式化列宽后)看起来像这样...
这里我们可以看到(对于 ORDERS 表)ORDER_ID 是主键,并且有两个引用 CUSTOMERS 的外键,并且分别是 EMPLOYEES 表。
Using the Oracle XE sample database. I wanted to identify the primary and foreign keys on a schema/table. Here's how...
The output (after formatting the column widths) looks like this...
Here we can that see that (for the ORDERS table) ORDER_ID is the primary key, and that there are two foreign keys referencing the CUSTOMERS, and the EMPLOYEES tables respectively.