I have two databases DB1 and DB2. In both databases exists this two tables mo_sms and mt_sms. This is the structure of those tables:
CREATE TABLE IF NOT EXISTS `mo_sms` (
`id_MO` int(11) unsigned NOT NULL AUTO_INCREMENT,
`sms_proceso` char(1) NOT NULL COMMENT 's=SMS c=CHAT d=Descargas',
`msisdn` varchar(20) NOT NULL,
`texto_sms` varchar(160) DEFAULT NULL,
`brand_id` int(10) unsigned NOT NULL,
`fecha_sms` datetime NOT NULL,
`comando_id` int(10) unsigned NOT NULL DEFAULT '0',
`alias_desc` varchar(25) DEFAULT NULL,
`shortcode_id` int(10) unsigned NOT NULL,
`precio` float(11,2) unsigned DEFAULT '0.00' COMMENT 'Precio del MO',
`id_user` int(10) unsigned NOT NULL,
`state` char(1) NOT NULL DEFAULT '0' COMMENT '0=Por procesar 1=Procesado',
`tipo_sms` tinyint(4) NOT NULL DEFAULT '0' COMMENT '0=Normal, <>0 dependera del tipopredeterminado',
`anio_sms` smallint(4) unsigned NOT NULL DEFAULT '0',
`mes_sms` smallint(2) unsigned zerofill NOT NULL DEFAULT '00',
PRIMARY KEY (`id_MO`),
KEY `ix_carrier` (`brand_id`),
KEY `ix_fecha_sms` (`fecha_sms`),
KEY `ix_fecha_carrier_keyword` (`fecha_sms`,`brand_id`,`alias_desc`),
KEY `ix_msisdn` (`msisdn`),
KEY `ix_sms_proceso` (`sms_proceso`),
KEY `ix_sms_proceso_state` (`sms_proceso`,`state`),
KEY `ix_id_user` (`id_user`),
KEY `ix_fecha_sms_user` (`fecha_sms`,`id_user`),
KEY `ix_varios` (`anio_sms`,`mes_sms`,`comando_id`,`shortcode_id`,`brand_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Tabla de MO' AUTO_INCREMENT=82972 ;
CREATE TABLE IF NOT EXISTS `mt_sms` (
`id_MT` int(11) unsigned NOT NULL AUTO_INCREMENT,
`sms_proceso` char(1) NOT NULL DEFAULT 'c' COMMENT 's=SMS c=CHAT d=Descargas',
`msisdn` varchar(20) NOT NULL,
`texto_sms` varchar(160) DEFAULT NULL,
`brand_id` int(10) unsigned NOT NULL,
`fecha_sms` datetime NOT NULL,
`comando_id` int(10) unsigned NOT NULL DEFAULT '0',
`alias_desc` varchar(25) DEFAULT NULL,
`shortcode_id` int(10) unsigned NOT NULL,
`id_user` int(10) unsigned NOT NULL,
`tipo_sms` tinyint(4) unsigned NOT NULL DEFAULT '0' COMMENT '0=Normal, <>0 dependera del tipopredeterminado',
`id_MO` int(11) unsigned NOT NULL,
`state` char(1) DEFAULT '0' COMMENT '0=Por Procesar 1=Procesado',
`anio_sms` smallint(4) unsigned NOT NULL DEFAULT '0',
`mes_sms` smallint(2) unsigned zerofill NOT NULL DEFAULT '00',
PRIMARY KEY (`id_MT`),
KEY `ix_carrier` (`brand_id`),
KEY `ix_fecha_sms` (`fecha_sms`),
KEY `ix_fecha_carrier_keyword` (`fecha_sms`,`brand_id`,`alias_desc`),
KEY `ix_msisdn` (`msisdn`),
KEY `ix_sms_proceso` (`sms_proceso`),
KEY `ix_id_user` (`id_user`),
KEY `ix_fecha_sms_user` (`fecha_sms`,`id_user`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Tabla de MT' AUTO_INCREMENT=93853;
I have some values in DB2 that should be migrated (inserted) in DB1. My problem here is I don't know how to get the records from DB2.mo_sms tables and those relations from DB2.mt_sms and then insert to DB1.mo_sms and DB2.mt_sms. For example I'll get all the records from mo_sms with fecha_sms LIKE '%2013-04-19%'
then if I insert those records in DB1.mo_sms new IDs will be generated then the integrity will be lost. Should I make this programatically or there is any way to do this using just SQL queries? I'm using MySQL as DBMS.
mt_sms.id_MO
the only relationship between this 2 tables ?