Cross-reference is a very useful tool in Dynamics AX, but cross-reference update requires a lot of time and resources. I want to share a simple way to copy cross-reference data.

Problem description
Copy cross-reference from one development environment to another, provided environments are identical.

Hints
Use bcp utility for export and import.

Solution
Cross-reference tables contain a lot of data, for example standard application with minor modifications in AX 2012 CU8:
XREFNAMES: 1.25 million records, 500MB space
XREFPATHS: 2.46 million records,  1400MB space
XREFREFERENCES: 14.35 million records, 6500MB space

Export
The following bat file can be used to export XREF* tables:

bcp MicrosoftDynamicsAX.dbo.XREFNAMES out XREFNAMES.txt -c -T
bcp MicrosoftDynamicsAX.dbo.XREFPATHS out XREFPATHS.txt -c -T
bcp MicrosoftDynamicsAX.dbo.XREFREFERENCES out XREFREFERENCES.txt -c -T
bcp MicrosoftDynamicsAX.dbo.XREFTABLERELATION out XREFTABLERELATION.txt -c -T

Where:
- MicrosoftDynamicsAX is Dynamics AX database name
- argument -c performs the operation using a character data type
- argument -T specifies that the bcp utility connects to SQL Server with a trusted connection using integrated security.

Export took 2 minutes, 4 *.txt files were created in the same folder:

Import
All records in XREF* tables must be deleted in destination database before import:
TRUNCATE TABLE XREFNAMES
TRUNCATE TABLE XREFPATHS
TRUNCATE TABLE XREFREFERENCES
TRUNCATE TABLE XREFTABLERELATION
The following bat file can be used to import XREF* tables:

bcp MicrosoftDynamicsAX.dbo.XREFNAMES in XREFNAMES.txt -c -T
bcp MicrosoftDynamicsAX.dbo.XREFPATHS in XREFPATHS.txt -c -T
bcp MicrosoftDynamicsAX.dbo.XREFREFERENCES in XREFREFERENCES.txt -c -T
bcp MicrosoftDynamicsAX.dbo.XREFTABLERELATION in XREFTABLERELATION.txt -c -T

Import took about 10 minutes.

Conclusion
Cross-reference can be copied in approximately 15 minutes from one development environment to another.