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. ActivePython2.7 +Firefly1.2.2+WIN7服务器搭建过程(已通过)

    原地址:http://www.9miao.com/question-15-54027.html 1.ActivePython2.7 版本(内部已经包含easy_install,pywin32)2.所需 ...

  2. scala学习-类与对象

    类 / 对象 [<快学Scala>笔记] 一.类 1.Scala中的类是公有可见性的,且多个类可以包含在同一个源文件中: class Counter{ private var value ...

  3. css3属性整理

    浏览器内核:主流内容主要有Mozilla(熟悉的有Firefox,Flock等浏览器).WebKit(熟悉的有Safari.Chrome等浏览器).Opera(Opera浏览器).Trident(讨厌 ...

  4. C++ DLL 模板 .

    C++ DLL 模板 1.使用VS2005创建Win32 DLL项目,选择空项目,然后加入CppDll.h和CppDll.cpp文件. 2.修改CppDll.h和CppDll.cpp文件使之成为需要的 ...

  5. HDU4608+模拟

    简单的模拟题. 暴力枚举 /* 模拟 */ #include<algorithm> #include<iostream> #include<string.h> #i ...

  6. 李洪强iOS开发之拓展篇—UIDynamic(简单介绍)

      iOS开发拓展篇—UIDynamic(简单介绍) 一.简单介绍 1.什么是UIDynamic UIDynamic是从iOS 7开始引入的一种新技术,隶属于UIKit框架 可以认为是一种物理引擎,能 ...

  7. [itint5]二叉树转换线索二叉树

    http://www.itint5.com/oj/#27 用了基于stack的中序遍历,记录一下last,就很简单了. #include <stack> /*树结点的定义(请不要在代码中定 ...

  8. PNG优化/压缩

    我们总是希望 PNG 图像的容量能够小些.小些.再小些.优化 PNG 图像,可以用以下几个工具: 1.Optipng Optipng 是命令行工具,直接在其后追加所需优化的 PNG 图像即可 2.Pn ...

  9. Cygwin安装时,选择163的源后出错:Unable to get setup.ini from <http://mirrors.163.com/cygwin/>

    [问题] 折腾: [记录]Cygwin下把make从v3.82换成v3.81 期间,选择了163的源,结果出错: Cygwin Setup Unable to get setup.ini from & ...

  10. 搜索引擎spam

    什么是SPAM?搜索引擎优化中的SPAM 在搜索引擎优化相关的文章中中经常遇到“SPAM”一词,SPAM通常用来指垃圾邮件,不过在搜索引擎营销中所说的SPAM是专门针对那些欺骗搜索引擎的信息.搜索引擎 ...