Sercan Ozdemir
Sercan Ozdemir

Reputation: 4692

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.

Upvotes: 1

Views: 31

Answers (1)

Andronicus
Andronicus

Reputation: 26046

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.

Upvotes: 1

Related Questions