如何检查 Oracle 中关系的模态/基数

发布于 2024-08-21 12:28:35 字数 108 浏览 12 评论 0原文

我正在尝试对 Oracle 中的数据库进行逆向工程。我已经能够找到与外键相对应的主键和引用完整性规则,但无法找到模态/基数规则的存储位置。

任何有关查看哪个表或示例查询的帮助将不胜感激。

I am attempting to reverse engineer a Database that is in Oracle. I have been able to find the main keys and the referential integrity rules that correspond to the Foreign Keys but cannot locate where the modality/cardinality rules are stored.

Any help regarding to which table to look in or a sample query would be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浅语花开 2024-08-28 12:28:35

模态/基数规则是什么意思?

对于 Oracle 而言,FK 关系始终是 1:N。我想可以通过在同一字段上但方向相反的两个 FK 关系来强制执行 1:1。

关于基数的唯一其他“规则”是唯一键,但我认为您已经拥有了这些。如果没有,这可能会有所帮助:

http://www.eveandersson.com /writing/data-model-reverse-engineering#constraints

根据数据库的设置,您还可能会发现有关列中值基数的启发式

select * from user_tab_col_statistics

尤其是值“NUM_DISTINCT”可能会有一定的价值。

如果您正在数据字典中寻找更多信息,我建议初学者选择此选项

select * from dict
where lower(comments|| '@' || table_name) like '%whatareyoulookingfor%'

What do you mean by modality / cardinality rules?

FK relationships are always 1:N as far as Oracle is concerned. I guess one could enforce a 1:1 by having two FK relationships on the same fields but in opposite directions.

The only other 'rule' concerning cardinality are unique keys, but I think you already have those. If not, this might help:

http://www.eveandersson.com/writing/data-model-reverse-engineering#constraints

Depending on the setup of the database you also might find heuristics about the cardinality of values in columns:

select * from user_tab_col_statistics

Especially the value 'NUM_DISTINCT' might be of some value.

If you are looking for more information in the data dictionary, I recommend this select for starters

select * from dict
where lower(comments|| '@' || table_name) like '%whatareyoulookingfor%'
荆棘i 2024-08-28 12:28:35

我认为您必须检查引用列是否可以为空:

SELECT column_name, nullable
FROM user_tab_cols
WHERE table_name = '<TABLE_NAME>'

以及引用列上的唯一索引:

SELECT idx.index_name, col.column_name
FROM user_indexes idx
JOIN user_ind_columns col ON ( col.index_name = idx.index_name )
WHERE idx.uniqueness = 'UNIQUE'
  AND idx.table_name = '<TABLE_NAME>'

I think you will have to check for referring columns being nullable:

SELECT column_name, nullable
FROM user_tab_cols
WHERE table_name = '<TABLE_NAME>'

and for unique indices on referring columns:

SELECT idx.index_name, col.column_name
FROM user_indexes idx
JOIN user_ind_columns col ON ( col.index_name = idx.index_name )
WHERE idx.uniqueness = 'UNIQUE'
  AND idx.table_name = '<TABLE_NAME>'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文