- First, open SSMS under Administrator.
- Second, using SSMS to backup the existing database.
- Third, copy the created backup file to the directory that your new database account have full accessing privilege. For example, if your new database instance is named as dw_dev, it should be by default C:\Program Files\Microsoft SQL Server\MSSQL11.dw_dev\backup\mydb.bak, unless you changed the default directory to somewhere else. Note you should copy your DB backup file here because this is the only place your database account have full access privilege.
You can also use SQL Server Configuration Manager to get the account name of your database service. And you can add the full access privilege for the specific directory of the backup file to the account name so that you don't need to do above copy.
- Forth, using following script to get physical file names for the data and log files of your database file.
RESTORE FILELISTONLY FROM DISK = 'C:\AdventureWorks.BAK' GOQuery result would be like:
LogicalName PhysicalName
mydb D:\Data\SQLEXPRESS\mydb.mdf
mydb_log D:\Data\SQLEXPRESS\mydb_log.ldf
- Fifth, using following script to get physical file names for the data and log files of your database file.
Note even you used Restore, there should be no same new database exist, otherwise, you need to delete the database before executing the following script.
RESTORE DATABASE AdventureWorks FROM DISK = 'C:\AdventureWorks.BAK' WITH MOVE 'AdventureWorks_Data' TO 'G:\SQLData\AdvnetureWorks_Data.mdf', MOVE 'AdventureWorks_Log' TO 'H:\SQLData\AdvnetureWorks_Log.ldf' GOResource: https://www.mssqltips.com/sqlservertutorial/122/retore-sql-server-database-to-different-filenames-and-locations/
No comments:
Post a Comment