ALTER TABLE `visits_medical_center` 
CHANGE COLUMN `serial_cmsp` `serial_cmsp` INT(11) NULL ;


CREATE TABLE `visit_medical_code_msp` (
  `serial_vmc` INT NOT NULL,
  `serial_cmsp` INT NOT NULL);


ALTER TABLE `visit_medical_code_msp` 
ADD INDEX `visita_idx` (`serial_vmc` ASC),
ADD INDEX `codigo_idx` (`serial_cmsp` ASC);
ALTER TABLE `visit_medical_code_msp` 
ADD CONSTRAINT `visita`
  FOREIGN KEY (`serial_vmc`)
  REFERENCES `visits_medical_center` (`serial_vmc`)
  ON DELETE NO ACTION
  ON UPDATE NO ACTION,
ADD CONSTRAINT `codigo`
  FOREIGN KEY (`serial_cmsp`)
  REFERENCES `code_msp` (`serial_cmsp`)
  ON DELETE NO ACTION
  ON UPDATE NO ACTION;



ALTER TABLE `code_msp` 
ADD COLUMN `description` VARCHAR(250) NULL AFTER `name`;

SET foreign_key_checks = 0;

ALTER TABLE `code_msp` 
CHANGE COLUMN `serial_cmsp` `serial_cmsp` INT(11) NOT NULL AUTO_INCREMENT ;

SET foreign_key_checks = 1;