First off, I see promotionid in your primary key definition but not listed as a field in the table. Second, appid and user id do not have NOT NULL set. You are always going to run into trouble if you allow NULL values in a key. If id is unique, then perhaps using id alone for the primary key would be good. Finally, if you want a constraint that userid can have only one appid, then perhaps the easiest way to do this is with a BEFORE INSERT OR UPDATE trigger.