2

如何将AdventureWorksLT2008数据库重命名为同时重命名AdventureWorksLT2008_old.ldf.mdf文件?

我想从sqlcmd. 它是本地服务器。我想用-E选项来做。我确实尝试过谷歌搜索,但结果对我不起作用。任何人都可以建议一种尝试过的方法。

有人可以帮忙吗?

4

1 回答 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);
于 2013-03-31T01:33:20.673 回答