I am trying to create an index and multiple foreign keys in mysql but when I Include the code below:
CREATE INDEX par_ind on Image_Question (SessionId,Questi
here i have sorted out your problem and worked fine for me
ALTER TABLE `question` CHANGE `QuestionId` `QuestionId` INT(11) NOT NULL, ADD PRIMARY KEY(`QuestionId`);
first i have changed the QuestionId
to primary key
ALTER TABLE `image_question` ADD INDEX `questionId` (`QuestionId`);
then added the index on QuestionId
of image_question
ALTER TABLE `question` ADD CONSTRAINT `FK_question` FOREIGN KEY (`QuestionId`)
REFERENCES `image_question` (`QuestionId`) ON DELETE NO ACTION ;
and then first relationship for QuestionId
works successfully
ALTER TABLE `question` CHANGE `SessionId` `SessionId` INT(11) NOT NULL;
ALTER TABLE `image_question` CHANGE `SessionId` `SessionId` INT(11) NOT NULL;
then changed the data type of SessionId
of both tables to int
ALTER TABLE `image_question` ADD INDEX `NewIndex1` (`SessionId`);
then added index on SessionId
of image_question
ALTER TABLE `image_question` ADD CONSTRAINT `FK_image_question` FOREIGN KEY (`SessionId`) REFERENCES `question` (`SessionId`) ON DELETE NO ACTION ;
and here is your second relationship for SessionId
hope it works fine for you also