CREATE TABLE REGISTRATION_NUMBER (
  ID_INTERNAL int(11) not null auto_increment,
  KEY_ROOT_DOMAIN_OBJECT int(11) not null default '1',
  KEY_REGISTRATION int(11) not null,
  NUMBER int(11) not null,
  PRIMARY KEY (ID_INTERNAL),
  KEY KEY_REGISTRATION (KEY_REGISTRATION),
  KEY KEY_ROOT_DOMAIN_OBJECT (KEY_ROOT_DOMAIN_OBJECT)
);

alter table REGISTRATION add column KEY_REGISTRATION_NUMBER int(11) default null;
alter table REGISTRATION add index (KEY_REGISTRATION_NUMBER);

insert into REGISTRATION_NUMBER (ID_INTERNAL, KEY_REGISTRATION, NUMBER)
select REGISTRATION.ID_INTERNAL, REGISTRATION.ID_INTERNAL, REGISTRATION.NUMBER from REGISTRATION
where REGISTRATION.NUMBER is not null;

update REGISTRATION set REGISTRATION.KEY_REGISTRATION_NUMBER = REGISTRATION.ID_INTERNAL
where REGISTRATION.NUMBER is not null;
