Reputation: 39456
I'm creating a database (MySQL) which will store information on Magic: The Gathering cards.
At the moment, I have the card names
as unique
, however I've realized just now that this is an issue with many cards being available across multiple editions, example:
I am also storing the edition that the card belongs to (as an ID that links to an editions
table).
Is it possible to define the combination of the two columns name
and edition
unique rather than just name
, so that I don't have issues when trying to insert both the above cards?
Upvotes: 1
Views: 114
Reputation: 2929
Yes, you can create compound unique indexes:
UNIQUE KEY `names_editions` (`name`,`edition`)
Upvotes: 1