Weird. Two questions, one for for MySQL and another for SQL Server, posted with 10 min difference, with essentially the same problem, albeit different details and OP.
https://dba.stackexchange.com/questions/276542/unique-like-constraint-in-a-complex-scenario
https://dba.stackexchange.com/questions/276540/mysql-constraint-to-prevent-combinations-of-columns