I'm creating a database which stores football matches.
Each round, any given football club may only play once (home or away).
For example, after the insert of
INSERT INTO Match (Round, Home, Away) VALUES (1, Barcelona, Real);
inserts such as
INSERT INTO Match (Round, Home, Away) VALUES (1, Bayern, Barcelona);
INSERT INTO Match (Round, Home, Away) VALUES (1, Barcelona, Bayern);
must be forbidden since Barcelona has already played one match against Real in Round 1. They shouldn't be able to play against Bayern in the same round (doesn't matter if they're playing home or away).
How can I ensure such inserts don't happen?
Do I use a trigger? Some sort of unique index combination? I've tried both but got lost and didn't actually get the outcome expected.
Thanks