Unique relationship attribute for every pair of entities
You would create a unique constraint on exam (StudentId, CourseId) this would usually be achieved with a unique index on that table that covered the two columns.
Here's a quick demo in MySql