Use ALTER DATABASE to Move Databases

Follow Our Daily Tips

facebook.com/TechNetTips
• twitter.com/TechNetTips
• blogs.technet.com/tnmag
• TechNet Tips library

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.

时间: 2024-10-24 05:21:55

Use ALTER DATABASE to Move Databases的相关文章

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>   <inf>Log Shrink</inf>   <Sql> --  ======================================================================== -- Shrink of log file E:\SQ

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

Hive Data Definition Language Hive Data Definition Language Overview Create/Drop/Alter Database Create/Drop/Truncate Table Alter Table/Partition/Column Create/Drop/Alter View Create/Drop/Alter Index Create/Drop Function Create/Drop/Grant/Revoke Roles

不完全回复-alter database open resetlogs

先要弄清楚alter database open resetlogs是什么意思,为什么要用resetlogs打开数据库,这个命令发出后oracle都做了什么? alter database open resetlogs是要打开数据时,重置重做日志,即将重做日志的sequence置零,为什么要重置重做日志呢? 不完全恢复后,原来的online redo log里面包含的是未做恢复前的数据,而这些数据对于恢复后的数据库不再有效,所以数据库会要求在Open之前先对online redo log的seq

【 翻译自mos文章】Alter Database Add Supplemental Log Data 命令挂起

Alter Database Add Supplemental Log Data 命令挂起 来源于: Alter Database Add Supplemental Log Data Hangs (文档 ID 406498.1) 适用于: Oracle Database - Enterprise Edition - Version 10.2.0.1 and later Information in this document applies to any platform. 症状: 作为流复制配

alter database open resetlogs

使用resetlogs选项,会把当前的日志序号(log sequence number)重设为1,并抛弃所有日志信息.在以下条件时需要使用resetlogs选项: 在不完全恢复(介质恢复): 使用备份控制文件. 使用resetlogs打开数据库后,务必要完整地进行一次数据库备份. 不完全恢复只能做一次吗? 采用rman的默认设置,对数据库进行了backup database备份,进行了一些操作后,然后直接关闭启动到mount状态 RMAN> run{ 2> set until time &qu

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

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

丢失所有控制文件,noresetlogs重建控制文件,alter database open

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

alter database和alter system和alter session的区别

1.system是实例级,database是数据库级,session是会话级. 2.关于这三个级别个更改大致如下 数据库级(比较大)> 实例级 > 会话级(仅针对当前对话) 3.相关属性 "alter session set *****=****"  //对当前会话有效 "alter system set *****=****"   //是永久(系统)有效 "alter database set *****=****"  //一般是改

ORA-01093: ALTER DATABASE CLOSE only permitted with no sessions connected

10.2.0.3环境下的DG主备切换演练,关闭应用且重启主库之后,主库查询切换状态: SQL> select switchover_status from v$database; SWITCHOVER_STATUS -------------------- SESSIONS ACTIVE 执行以下命令尝试切换 SQL> ALTER DATABASE COMMIT TO SWITCHOVER TO PHYSICAL STANDBY; 报错如下: 同时,alert日志报错很多SYSTEM 用户的进