【问题标题】:Renaming SQL Server database from SQLCMD从 SQLCMD 重命名 SQL Server 数据库
【发布时间】:2013-03-30 23:24:04
【问题描述】:

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

我想从sqlcmd 开始。它是本地服务器。我想用-E 选项来做。我确实尝试过谷歌搜索,但结果对我不起作用。谁能推荐一个尝试过的方法。

有人可以帮忙吗?

【问题讨论】:

    标签: sql-server database sqlcmd


    【解决方案1】:

    快速的谷歌搜索得到this 作为最高结果。您所要做的就是从 sqlcmd 开始(我假设您知道如何使用 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);
    

    【讨论】:

      猜你喜欢
      • 2016-01-11
      • 2012-09-11
      • 1970-01-01
      • 1970-01-01
      • 2015-08-20
      • 1970-01-01
      • 2021-08-29
      • 2011-12-04
      • 2018-01-27
      相关资源
      最近更新 更多