Last week, Microsoft MVP Ian Grieve discussed on his Azure Curve blog changing the logical file names of SQL databases in Microsoft Dynamics GP. When a SQL database is created, a logical name will be assigned to it, and that logical name will match the physical name. However, as Grieve points out, “When working with Microsoft Dynamics GP, we often create both a live and test database and then populate the settings in the live database and replicate over the top of the test one.”
Another complicating example that Grieves offers is when you create a template database, which then gets copied when a new company is created. This method might be used if you have a substantial amount of setup in third party modules for which the PSTL Company Copy doesn’t work.
These two scenarios both lead to the same problem: when a database is restored elsewhere, it will bring its logical name with it, and that means that a mismatch between the logical and physical names will occur, which in turn causes problems when backing up and restoring databases.
But worry not, because you can change the logical name of a database with a simple SQL script. Use two “ALTER DATABASE” commands, one to change the name of the data file and another to change the name of the log file. Grieve reminds that “as always, when running a SQL script against a database, make sure you have a good backup and perform a test afterward to make sure there are no problems.”