英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论