For what is worth :
The following is a script which I schedule as a DTS package at a few clients to nightly backup their primary ES company and restore it to an existing test company. As it is a test company, changing the company number everwhere is not done.
Exact does embed the company number in the GBKMUT, BankTransactions, CICMPY among other places. If you want to consolidate data across companies then chaning the company number in these tables becomes important. Gives you a refernce as to which company the data is coming from and deals with duplicate Debitor / Creditor Number across multiple databases.
I only change the company name in the Bedryf table, which is displayed on the login screen, and reports.
You may need to adjust the Physical file names, Logical File Names, directories, and paths.
Script :
--Makes sure that current DB is not 199
Use Master
--Backs up 100 to a file
BACKUP DATABASE [100] TO DISK = N'C:\backup.bak' WITH INIT , NOUNLOAD , NAME = N'100 backup', NOSKIP , STATS = 10, NOFORMAT
--Inorder to restore, changes target to single user mode
ALTER DATABASE [199] SET SINGLE_USER WITH ROLLBACK IMMEDIATE
--Restores database 100 to database 199
RESTORE DATABASE [100] FROM DISK = N'C:\backup.bak' WITH FILE = 1, NOUNLOAD , STATS = 10, RECOVERY , REPLACE , MOVE N'100_Data' TO N'C:\Program Files\Microsoft SQL Server\MSSQL\data\199_Data.MDF', MOVE N'199_Log' TO N'C:\Program Files\Microsoft SQL Server\MSSQL\data\199_Log.LDF'
--Changes the Logical File Name in SQL
USE "199"
GO
ALTER DATABASE [199]
MODIFY FILE
(NAME = '100_Data', NEWNAME='199_Data')
GO
--Switches the database back to multi user mode
ALTER DATABASE "199" SET MULTI_USER WITH ROLLBACK IMMEDIATE
--Deletes the Backup File
exec master.dbo.xp_cmdshell "del c:\backup.bak"
--Updates the Company Name in Macola ES
use [199]
update bedryf set bedrnm = '"*** 199 TEST ***' + CAST(GETDATE() AS nvarchar(30))