如何将AdventureWorksLT2008
数据库重命名为同时重命名AdventureWorksLT2008_old
其.ldf
和.mdf
文件?
我想从sqlcmd
. 它是本地服务器。我想用-E
选项来做。我确实尝试过谷歌搜索,但结果对我不起作用。任何人都可以建议一种尝试过的方法。
有人可以帮忙吗?
如何将AdventureWorksLT2008
数据库重命名为同时重命名AdventureWorksLT2008_old
其.ldf
和.mdf
文件?
我想从sqlcmd
. 它是本地服务器。我想用-E
选项来做。我确实尝试过谷歌搜索,但结果对我不起作用。任何人都可以建议一种尝试过的方法。
有人可以帮忙吗?
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);