Hello.
There is a table with a unique composite index of 2 fields, here’s a query to create it:
CREATE TABLE `test` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `field1` int(11) unsigned DEFAULT NULL, `field2` int(11) unsigned NOT NULL, `field3` int(10) unsigned NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `uniq` (`field1`,`field2`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; I don’t understand why I can add the same records, provided that the field1 field is NULL. Here is an example of filling the table:
INSERT INTO `test` (`id`, `field1`, `field2`, `field3`) VALUES (1, 1, 1, 1), (3, 1, 2, 1), (4, NULL, 1, 1), (5, NULL, 1, 1), (6, NULL, 1, 1);