2

How can I rename AdventureWorksLT2008 database to AdventureWorksLT2008_old with its .ldf and .mdf files renamed as well?

I would like to do it from sqlcmd. It is a local server. I would like to do it with -E option. I did try googling but results didn't work for me. Can anyone suggest a tried method.

Can anyone please help?

1 Answer 1

1

a quick google search got this as the top result. All you have to do is to everything from sqlcmd( I am assuming you know how to use sqlcmd..)

-- Replace all MyDBs with the name of the DB you want to change its name
USE [MyDB];
-- Changing Physical names and paths
-- Replace all NewMyDB with the new name you want to set for the DB
-- Replace 'C:\...\NewMyDB.mdf' with full path of new DB file to be used
ALTER DATABASE MyDB MODIFY FILE (NAME = ' MyDB ', FILENAME = 'C:\...\NewMyDB.mdf');
-- Replace 'C:\...\NewMyDB_log.ldf' with full path of new DB log file to be used
ALTER DATABASE MyDB MODIFY FILE (NAME = ' MyDB _log', FILENAME = 'C:\...\NewMyDB_log.ldf');
-- Changing logical names
ALTER DATABASE MyDB MODIFY FILE (NAME = MyDB, NEWNAME = NewMyDB);
ALTER DATABASE MyDB MODIFY FILE (NAME = MyDB _log, NEWNAME = NewMyDB_log);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.