Skip to content
Advertisement

Postgresql create trigger for integrity constraint in insert / update

I have these tables on a database on Postgresql:

I want to be sure that when I insert / update a value in manager_employee table both manager_id and employee_id belong to the same company, same company_id.

I think I have to use a trigger to ensure this condition, how can I create it?

Thanks

Advertisement

Answer

You can do it with constraints:

The unique constraint is as redundant as the new column, but is required as a target for the foreign key constraint.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement