信息模式,如何检索链接表
我正在编写一个可以基于数据库创建数据仓库的脚本。为了识别所有集线器,我需要一个查询来提供链接表的名称(多对多)。
做到这一点的最佳方法是什么:
找到代理键还是我必须分析它们来自和去向的关系?
预先感谢您
I'm wokring on a script that can create a data vault based on a database. To identify all the hubs i need a query that gives me the name of the link tables (many-to-many).
what is the best way to do this:
find surrogate keys or do I have to analyse the relations where they come from and where they go to?
Thank you in afvanced
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在多对多中,您可以依靠外键的存在。您不能指望代理键的存在。
至少,我认为您需要识别具有
的表,以及至少两列具有对其他表的外键引用的列。
如果您的平台支持 information_schema 视图,您可能需要查看其中的一个或多个。
我认为这将为您提供 PostgreSQL 中具有复合主键的表。可能会帮助您入门。
(如果我这样做,我会从此查询创建一个视图。另一个用于外键引用。对它们的连接应该非常简单。)
In a many-to-many, you can count on the existence of foreign keys. You can't count on the existence of surrogate keys.
At the very least, I think you'll need to identify tables that have
together with at least two columns that have foreign key references to other tables.
If your platform supports information_schema views, you'll probably need to look at one or more of these.
I think this will give you the tables that have a compound primary key in PostgreSQL. Might help get you started.
(If I were doing this, I'd create a view from this query. Another for foreign key references. Joins on them should be dead simple.)