Merge records in global address book

Q1: In AX 2012 GAB, how can we merge party id corresponds to same Address Name, exist in different companies? Records range in thousands hence can’t use (out-of-box)OOB functionality of merging records.Has anybody developed some AX script to handle this situation?

Q2: Also OOB functionality avaliable at {Home>Common>Global adress book> select record and merge} is not working. It is throwing error " Internal organisation party records cannot be merged" even if i try to merge customer in different Legal etities?

Request fellow folks to help on above two issues.

Q1 If i force to merge partyid through SQL query. Wht all tables i should be looking at so that data integrity is not disturbed?

Q2 What condition AX checks in database/table to know whether an record is Internal organisation party records?