Quantcast
Channel: MySQL Forums - InnoDB
Viewing all articles
Browse latest Browse all 1954

Add index on same field as other index drops other index (no replies)

$
0
0
When I add an index that has the same fields as another existing index, the existing index disappears.
I am trying to rename the indexes that are generated by creating an FK.
MySQL 5.5.24
Here is sample code that fails:

CREATE TABLE `table1` (
`sid` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) NOT NULL,
PRIMARY KEY (`sid`),
UNIQUE KEY `uq_table1` (`name`)
) ENGINE=InnoDB AUTO_INCREMENT=3823 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
CREATE TABLE `table2` (
`sid` int(11) NOT NULL AUTO_INCREMENT,
`table1_sid` int(11) NOT NULL,
PRIMARY KEY (`sid`),
UNIQUE KEY `uq1_table1_sid` (`table1_sid`),
CONSTRAINT `fk_table2_to_table1` FOREIGN KEY (`table1_sid`) REFERENCES `table1` (`sid`)
) ENGINE=InnoDB AUTO_INCREMENT=128 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
ALTER TABLE table2 DROP INDEX uq1_table1_sid, DROP FOREIGN KEY fk_table2_to_table1;
ALTER TABLE table2 ADD CONSTRAINT fk_table2_to_table1 FOREIGN KEY (table1_sid)
REFERENCES table1 (sid);
CREATE INDEX `fk_table2_to_table1_idx` ON `table2` (`table1_sid` ASC) ;

ALTER TABLE `table2` DROP INDEX `fk_table2_to_table1`;

Result: The last statement gets:

ERROR 1091 (42000) at line 28: Can't DROP 'fk_table2_to_table1'; check that column/key exists

Viewing all articles
Browse latest Browse all 1954

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>