Fixed database synchronization to handle tables with multiple ids