By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
create table exam (StudentID int, CourseID int , Grade char(1));
create unique index exam_uix_student_course on exam (StudentId, CourseId);
insert into exam values (1,1,'A');
insert into exam values (2,1,'B');
insert into exam values (3,2,'C');
insert into exam values (1,1,'B');
Duplicate entry '1-1' for key 'exam.exam_uix_student_course'