ALTER TABLE `query` ADD COLUMN `FileName` VARCHAR(256) NULL DEFAULT NULL; ALTER TABLE `query` ADD COLUMN `ExportTitle` VARCHAR(256) NULL DEFAULT NULL; CREATE TABLE `image` ( `Oid` bigint(19) NOT NULL AUTO_INCREMENT, `CustomerOid` bigint(19) DEFAULT NULL, `EmployeeOid` bigint(19) DEFAULT NULL, `InsTs` datetime DEFAULT NULL, `InsUser` varchar(256) DEFAULT NULL, `Notice` varchar(1024) DEFAULT NULL, `Tid` int(10) DEFAULT NULL, `UpdUser` varchar(256) DEFAULT NULL, `Version` bigint(19) DEFAULT NULL, `IsActive` tinyint(4) DEFAULT NULL, `SystemEntryID` int(10) DEFAULT NULL, `Original` longblob, `MediumThumbnail` longblob, `SmallThumbnail` longblob, PRIMARY KEY (`Oid`), KEY `KEY_CUSTOMER` (`CustomerOid`), KEY `KEY_EMPLOYEE` (`EmployeeOid`), CONSTRAINT `FK_CUSTOMER` FOREIGN KEY (`CustomerOid`) REFERENCES `customer` (`Oid`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `FK_EMPLOYEE` FOREIGN KEY (`EmployeeOid`) REFERENCES `employee` (`Oid`) ON DELETE NO ACTION ON UPDATE NO ACTION ) ENGINE=InnoDB AUTO_INCREMENT=38 DEFAULT CHARSET=latin1; insert into image (customeroid, isactive, version, original, insts, insuser, upduser) SELECT oid,1,1,customerimage,now(),'Mig', 'Mig' FROM customer where customerimage is not null; ALTER TABLE `image` ADD COLUMN `PersonOid` bigint(19) DEFAULT NULL; update image set personoid = (select personoid from customer c where c.oid = customeroid) where customeroid is not null and personoid is null update image set personoid = (select personoid from employee e where e.oid = employeeoid) where employeeoid is not null and personoid is null