The behavior of foreign keys can be finely tuned to your application. we will not go beyond this simple example in this tutorial, but just refer you to chapter 5 for more information. making correct use of foreign keys will definitely improve the quality of your database applications, so you are strongly encouraged to learn about them.. Create table t1 ( a integer primary key, b integer, c integer, foreign key (b, c) references other_table (c1, c2)); of course, the number and type of the constrained columns need to match the number and type of the referenced columns. you can assign your own name for a foreign key constraint, in the usual way.. How do the postgres foreign key 'on update' and 'on delete' options work? ask question. if you update the table and the field have a fk with on update, if a change is made on the fk you will be noticed on the fk table. browse other questions tagged sql database-design postgresql foreign-keys cascade or ask your own question. asked. 10.
If you do need to change them for some reason, then define proper foreign key constraints for the tables in question. then define the foreign keys to be on update cascade. this will "cascade" changes to all affected changes when a primary key changes.. In this post, i am sharing one option to disable / enable the foreign key constraint in postgresql. during data migration and testing purpose, database developer requires to disable foreign key constraint of a table.. Updating primary keys in postgresql. ask question. problem is that the table is heavily referenced by foreign keys from other tables: update b set a_new_id = a.new_id from a where b.a_id = a.id; to do a joined update, setting the new id values in b.a_new_id to match..