I want to create table with foreign keys.
This is scheme of this table:
CREATE TABLE `SupplierOrderGoods` (
`shopOrder_id` INT(11) NOT NULL,
`supplierGood_id` INT(11) NOT NULL,
`count` INT(11) NOT NULL,
PRIMARY KEY (`shopOrder_id`, `supplierGood_id`),
CONSTRAINT `FK_SupplierOrderGoods_ShopOrders` FOREIGN KEY (`shopOrder_id`) REFERENCES `shoporders` (`id`),
CONSTRAINT `FK_SupplierOrderGoods_SupplierGoods` FOREIGN KEY (`supplierGood_id`) REFERENCES `suppliergoods` (`id`)
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB;
It has two links: to table SupplierGoods
— FK_SupplierOrderGoods_SupplierGoods
and to table ShopOrders
— FK_SupplierOrderGoods_ShopOrders
. When I execute this code either in HeidiSQL or in phpMyAdmin odd index FK_SupplierOrderGoods_SupplierGoods
is being created.
I don't specify it in my scheme, but it is being created. I realized it when I had seen this in HeidiSQL:
Also, there are possibility to see create-code of the table in heidi:
CREATE TABLE `SupplierOrderGoods` (
`shopOrder_id` INT(11) NOT NULL,
`supplierGood_id` INT(11) NOT NULL,
`count` INT(11) NOT NULL,
PRIMARY KEY (`shopOrder_id`, `supplierGood_id`),
------> INDEX `FK_SupplierOrderGoods_SupplierGoods` (`supplierGood_id`),
CONSTRAINT `FK_SupplierOrderGoods_ShopOrders` FOREIGN KEY (`shopOrder_id`) REFERENCES `shoporders` (`id`),
CONSTRAINT `FK_SupplierOrderGoods_SupplierGoods` FOREIGN KEY (`supplierGood_id`) REFERENCES `suppliergoods` (`id`)
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB;
I didn't specify INDEX
, but it is here. I am scared... Why ? :'(
Why this index appears? I think my heidi is broken, so tried in phpmyadmin, but got same result.
I thinked if it can be correct... but why only 1 index for only 1 field? Why not two indexes if it is correct?
Update
Wow! I just realized, that all tables with foreign key has index! I googled it and found this. So it it normal, that index is being created with fk, right?
Then, why only 1 index is being created, but not two???