I have a stock table, with products:
STOCK_ID | SUPPLIER_ID | ITEM_ID
1 | 1 | 1
2 | 1 | 2
3 | 1 | 3
4 | 2 | 1
5 | 2 | 2
6 | 2 | 3
I want a constraint that will stop anyone from being able to add an item_id that already exists for a supplier. So in other words, in the example above, I must be able to add item_id 4 for supplier 1 and 2. But I must not be able to add another entry of items 1- 3 for either supplier 1 or 2.
I'm not sure what this is called or how you create such a limitation. But I know you can stop the user at a DB level from entering data like this. I basically want to put a block in place from adding data to the DB that an entry technically already exists for.
How do I do this in MySQL?