CREATE TABLE IF NOT EXISTS `Realm` (
  `Id` int(11) NOT NULL auto_increment,
  `Name` varchar(255) NOT NULL,
  `Database` int(11) NOT NULL,
  `Server` int(11) NOT NULL,
  `NetworkPortWorldd` int(11) NOT NULL,
  `Motd` varchar(255) NOT NULL,
  `Description` text NOT NULL,
  `Type` int(11) NOT NULL,
  `Homepage` varchar(255) NOT NULL,
  `TimeCreate` datetime NOT NULL,
  `Online` int(11) NOT NULL,
  `CharacterOnlineCount` int(11) NOT NULL,
  `CharacterCount` int(11) NOT NULL,
  `AccountCount` int(11) NOT NULL,
  `Lock` int(11) NOT NULL,
  PRIMARY KEY  (`Id`),
  KEY `Database` (`Database`),
  KEY `Server` (`Server`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

ALTER TABLE `Realm`
  ADD CONSTRAINT `Realm_ibfk_1` FOREIGN KEY (`Server`) REFERENCES `Server` (`Id`);
ALTER TABLE `Realm` ADD FOREIGN KEY ( `Database` ) REFERENCES `Database` (`Id`);

INSERT INTO `Realm` (SELECT 0 AS `Id`, "" AS `Name`, `Server`.`Database` AS `Database`, `Server`.`Id` AS `Server`, `NetworkPortWorldd`, `Motd`, "" AS `Description`, `Type`, "" AS `Homepage`, `TimeCreate`, 0 AS `Online`, `CharacterOnlineCount`, `CharacterCount`, `AccountCount`, 0 AS `Lock` FROM `Server`);

ALTER TABLE `Server` DROP `NetworkPortWorldd` , DROP `Motd` , DROP `Type` ;
