创建外键是否会修改引用的表?

huangapple go评论97阅读模式
英文:

Does creating foreign key alter the referenced table?

问题

The question is clear I suppose, I'm working with PostgreSQL 12, thanks in advance.

I don't want to update the referenced table (huge data set) and creating a new one by creating a foreign key to referencing a huge table. So I can't alter the referenced table.

英文:

The question is clear I suppose, I'm working with postgresql 12, thanks in advance.

I don't want to update the referenced table (huge data set) and creating a new one by creating a foreign key to referencing a huge table. So I can't alter the referenced table.

答案1

得分: 1

不,它不会直接影响表格。

尽管操作引用的表格可能会导致约束违规。例如,如果引用表的任何行指向被引用的表,并且您想删除后者,那么将会引发异常。您必须首先解除关系。

附注:还要小心像Hibernate这样的映射框架 - 您需要正确定义关系,以防止将任何更改级联到父表。

英文:

No, it does not affect the table directly.

Although manipulating the referenced table might cause constraint violations. For example, if any rows from the referencing table point to the referenced table and you would like to drop the latter, an exception would be raised. You would have to get rid of relationships first.

P.S.: Also, be careful with mapping frameworks like hibernate - you need to define the relationship correctly not to cascade any changes to the parent table.

huangapple
  • 本文由 发表于 2020年1月6日 16:14:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/59608704.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定