TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: Why is there no datatype “rows of (another) table” in databases?

3 点作者 miclill超过 10 年前
This way we could still do: 1<->M M<->M 1<->1 No more handeling of IDs and if you don't want the DB to do the "implicit join" just omit the column. Would we loose any kind of flexibility? I strongly suspect that I am missing something here but I don't know how to find information / search for it.

2 条评论

andyjpb超过 10 年前
This is typed in the foreign key constraints DDL.<p>Often a foreign key will refer to rows in more than one other table. Not all queries will want to chase all of those references.<p>Moreover, when you have a composite key, the foreign part may only be a subset of the entire key.<p>For example, if your Key is {Street,House}, you have a relation to another table which has a list of people inside that {Street,House} and you might also have a relation on {Street} to a table that contains metadata about that street as a whole.<p>The &quot;Type&quot; of the &quot;row in another table&quot; isn&#x27;t a single thing: it would be different for all the different relations so it exists in the form of foreign key declarations which embody all the variability in the relation.
评论 #8768641 未加载
GFischer超过 10 年前
As andyjpb said, it&#x27;s encoded in the foreign key.<p>Many ORMs have capabilities for &quot;implicit joins&quot; with either lazy or eager loading of the foreign rows, for example the latest Entity Framework from Microsoft.<p><a href="http://msdn.microsoft.com/en-us/data/jj713564.aspx" rel="nofollow">http:&#x2F;&#x2F;msdn.microsoft.com&#x2F;en-us&#x2F;data&#x2F;jj713564.aspx</a><p>If you like that kind of &quot;automagic&quot; things, check out Genexus:<p><a href="http://www.genexus.com/global/home?en" rel="nofollow">http:&#x2F;&#x2F;www.genexus.com&#x2F;global&#x2F;home?en</a><p>it&#x27;s a 4GL programming environment that has as one of its main strengths that kind of implicit joins and automatic retrieval of data you mention, as long as you follow the naming conventions.<p>It&#x27;s a REALLY fast way to build your standard line-of-business application (and it automatically generates iOS and Android apps too), but it falls apart for any other use, and it&#x27;s UI is not that flexible usually.