Use ALTER DATABASE to Move Databases

You can use the ALTER DATABASE statement to move any system or user-defined database files except for Resource database files.To move files, you specify the cur¬rent logical name of the file and the new file path, which includes the new file name.You can move only one file at a time in this manner.

To move data or log files to a new location, follow these steps:

1. Get the logical name of the data and log files associated with the database by typing the following:

USE master
SELECT name, physical_name
FROM sys.master_files
WHERE database_id = DB_ID("Personnel");
2. Take the database you want to work with offline by typing these commands:
ALTER DATABASE Personnel
SET offline
GO
3. Move one file at a time to the new location by typing the following:
ALTER DATABASE Personnel
MODIFY FILE ( NAME = Personnel_Data, FILENAME =
"C:\Data\Personnel_Data.mdf")
GO
4. Repeat the previous step to move other data and log files.

5. Put the database online by typing the following commands:

ALTER DATABASE Personnel
SET online
GO

You can verify the change or changes by typing this:

USE master
SELECT name, physical_name
FROM sys.master_files
WHERE database_id = DB_ID("Personnel");

You can also move full-text catalogs by their logical name. But note that when you specify the new catalog location, you specify only new_path rather than new_path/file_name.To move a full-text catalog file to a new location, follow these steps:

1. Take the database you want to work with offline by typing the following:

ALTER DATABASE database_name
SET offline
GO
2. Move one file at a time to the new location by typing these commands:
ALTER DATABASE database_name
MODIFY FILE ( NAME = logical_name, FILENAME = "new_path".
GO
3. Repeat the previous step to move other full-text catalog files as necessary.

4. Put the database online by typing the following:

ALTER DATABASE database_name
SET online
GO
For more on using ALTER DATABASE, see the tip Change Settings with ALTER DATABASE in SQL Server 2008.

From the Microsoft Press book Microsoft SQL Server 2008 Administrator’s Pocket Consultant, Second Edition by William R. Stanek.

Use ALTER DATABASE to Move Databases的更多相关文章

  1. backup, file manipulation operations (such as ALTER DATABASE ADD FILE) and encryption changes on a database must be serialized.

    昨天在检查YourSQLDba备份时,发现有台数据库做备份时出现了下面错误信息,如下所示: <Exec>   <ctx>yMaint.ShrinkLog</ctx> ...

  2. [Hive - LanguageManual] Create/Drop/Alter Database Create/Drop/Truncate Table

    Hive Data Definition Language Hive Data Definition Language Overview Create/Drop/Alter Database Crea ...

  3. 非域环境下搭建自动故障转移镜像无法将 ALTER DATABASE 命令发送到远程服务器实例的解决办法

    非域环境下搭建自动故障转移镜像无法将 ALTER DATABASE 命令发送到远程服务器实例的解决办法 环境:非域环境 因为是自动故障转移,需要加入见证,事务安全模式是,强安全FULL模式 做到最后一 ...

  4. 由于无法在数据库 'TestNonContainedDB' 上放置锁 ALTER DATABASE 失败

    Error: 消息5601,级别16,状态1,第1行,由于无法在数据库 'TestNonContainedDB' 上放置锁,ALTER DATABASE 失败.请稍后再试.消息5069,级别16,状态 ...

  5. 丢失全部控制文件,noresetlogs重建控制文件,alter database open

    測试2: (1)一致性的全备 SQL> shutdown immediate; $ cp -rf $ORACLE_BASE/oradata/boss/*.dbf /oradata/bossbak ...

  6. alter database open resetlogs

    使用resetlogs选项,会把当前的日志序号(log sequence number)重设为1,并抛弃所有日志信息.在以下条件时需要使用resetlogs选项: 在不完全恢复(介质恢复): 使用备份 ...

  7. ORA-01093: ALTER DATABASE CLOSE only permitted with no sessions connected解决方法

    在进行物理主备库角色转换的时候遇到ORA-01093错误 SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY; ALTER ...

  8. Oracle DG故障诊断一则:alter database recover to logical standby new_logical_dbname卡住

    我们在基于物理standby的基础上搭建逻辑备库过程过程中,在运行: alter database recover to logical standby READDB; 卡住不动,而且alert也没有 ...

  9. ORA-279 signalled during: alter database recover logfile

    在RMAN的RECOVER还原过程中,RMAN界面正常,但是检查.刷新告警日志,发现告警日志里面有ORA-279,如下所示: alter database recover logfile '/u06/ ...

随机推荐

  1. Scala中的Extractor

    Scala中使用unapply方法可以实现三种extractor(另外使用unapplySeq也可以实现extractor) def unapply(object: S): Option[(T1, . ...

  2. mysql数据库备份执行计划

    为什么需要数据备份?如果数据库因为人为或其他不可控的因素导致数据库数据丢失或损坏,导致的后果将会非常严重. 为什么需要执行计划?备份操作如果每天人工管理的话,将会非常麻烦,需要借助工具来制定执行计划, ...

  3. _CrtIsValidPointer 问题

    从微软站点: 检查指针有效性下面的示例使用 _CrtIsValidPointer 验证给定的内存范围对于读或写是否有效. _ASSERTE(_CrtIsValidPointer( address, s ...

  4. 一个简单的C#加密解密类

    //DES默认密钥向量 private static byte[] Keys = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF }; /// < ...

  5. codeforces #305 D Mike and Fish

    正解貌似是大暴搜? 首先我们考虑这是一个二分图,建立网络流模型后很容易得出一个算法 S->行 容量为Num[X]/2; 行->列 容量为1 且要求(x,y)这个点存在 列->T 容量 ...

  6. 关于Application.Lock和Lock(obj)

    http://www.cnblogs.com/yeagen/archive/2012/03/01/2375610.html 1.Application.Lock和Application.UnLock一 ...

  7. classpath、path、JAVA_HOME的作用及JAVA环境变量配置

    CLASSPATH是什么?它的作用是什么? 它是javac编译器的一个环境变量.它的作用与import.package关键字有关.当你写下improt java.util.*时,编译器面对import ...

  8. C++中的namespace用法

    关键字namespace定义了一个名字空间,里面的变量和函数,声明在此名字空间外使用须在前面加名字空间名称.例如: #include<iostream.h>namespace my{ in ...

  9. BIG5编码表

    Big5 (Traditional Chinese) character code table code +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +A +B +C +D +E +F ...

  10. sublime text格式化插件

    sublime text 软件其实是自带格式化插件的,但是它默认的格式化插件,不太好用,且没有快捷键(虽然自己可以设置). 其默认的格式化是在 Edit  ->  Line  ->  Re ...