I have table stucture:
table {
`id` int(11) NOT NULL AUTO_INCREMENT,
`content_type`,
`protocol`,
`content_id`,
`hash`
}
I’m adding unique key
alter table delivery add unique (content_type, protocol, content_id, hash);
How can i avoid duplication of keys if run query X-times;
Example:
UNIQUE KEY `content_type_2` (`content_type`,`protocol`,`content_id`,`hash`),
UNIQUE KEY `content_type_3` (`content_type`,`protocol`,`content_id`,`hash`),
UNIQUE KEY `content_type_4` (`content_type`,`protocol`,`content_id`,`hash`),
UNIQUE KEY `content_type_5` (`content_type`,`protocol`,`content_id`,`hash`),
UNIQUE KEY `content_type_6` (`content_type`,`protocol`,`content_id`,`hash`),
UNIQUE KEY `content_type_7` (`content_type`,`protocol`,`content_id`,`hash`),
UNIQUE KEY `content_type_8` (`content_type`,`protocol`,`content_id`,`hash`),
UNIQUE KEY `content_type_9` (`content_type`,`protocol`,`content_id`,`hash`),
UNIQUE KEY `content_type_10` (`content_type`,`protocol`,`content_id`,`hash`),
UNIQUE KEY `content_type_11` (`content_type`,`protocol`,`content_id`,`hash`),
UNIQUE KEY `content_type_12` (`content_type`,`protocol`,`content_id`,`hash`),
Use a named constraint, which should fail if you attempt to create the same constraint twice:
ALTER TABLE delivery ADD CONSTRAINT my_constraint_name UNIQUE (content_type, protocol, content_id, hash);