This script is a solution for copying companies between databases on the same server or between linked servers. It can also be used to downgrade a SQL database from 2012 to 2008.
Since the Backup and Restore feature has been removed in NAV 2013 R2, I was searching for an alternative way to copy companies between databases. Among the goals were to support linked servers and to be a SQL only solution which could potentially be automated later on.
Usage:
1) Create an exact copy of the source database, all tables must be identical. Importing the objects as FOB is fine. This will be the destination database
2) Connect to the new database using the Windows Client and create a new Company. It must have exactly the same name as the Company in the source database
3) Open this script in a new Query Window in SQL Server Management Studio
4) Set the name of the destination database below ("USE DATABASENAME...")
5) Scroll down and set the name of the source database. You may also specify a linked server if the source database is on a remote SQL Server
6) Set the name of the company to copy
7) Optional: Specify all the DataPerCompany=No tables that you want to copy along by adding one "EXECUTE NAVCopyTable..." per table. Examples can be found below
8) Run the script to start the copy