I have the following schema in PostgreSQL
CREATE TABLE exam (
exam_id INT,
exam_name TEXT,
total_marks INT,
PRIMARY KEY(exam_id)
);
CREATE TABLE studentmarks (
studentmarks_id INT,
student_id INT,
exam_id INT,
marks_scored INT,
PRIMARY KEY(studentmarks_id),
FOREIGN KEY(exam_id) REFERENCES exam ON DELETE SET NULL,
);
How can I enforce the constraint that studentmarks.marks_scored <= exam.total_marks such that the behaviour is just like the CHECK constraint?
exam.total_marksbelow an existingstudentmarks.marks_scored?CHECK (...)constraint in PostgreSQL