Skip to content
Advertisement

Adding constraint in PostgreSQL that requires information from another table

I have the following schema in PostgreSQL

How can I enforce the constraint that studentmarks.marks_scored <= exam.total_marks such that the behaviour is just like the CHECK constraint?

Advertisement

Answer

Use trigger.

You need to create trigger function first.

Then create trigger.

NOTE I have tested in postgres

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