SQL Server 2008如何copy database:
方法一:使用Microsoft SQL Server Management Studio中的Copy Database Wizard来辅助完成。(很容易失败)
方法二:采取Backup/Restore的方式(推荐)
a.备份数据库到磁盘
BACKUP DATABASE Source_Database TO DISK = 'D:\Backup\Source_Database.bak' WITH FORMAT;
b.查看备份文件的逻辑文件
RESTORE FILELISTONLY FROM DISK = 'D:\Backup\Source_Database.bak';
c.创建目标数据库
CREATE DATABASE Target_Database;
d.从磁盘复制数据库
/* 利用bak恢复数据库,强制还原(REPLACE) STATS = 10 每完成10%显示一条记录 Source_Database和Source_Database_log是上面D:\Backup\Source_Database.bak里的逻辑文件 */ RESTORE DATABASE Target_Database FROM DISK='D:\Backup\Source_Database.bak' WITH MOVE 'Source_Database' TO 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\Target_Database.mdf', MOVE 'Source_Database_log' TO 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\Target_Database_log.ldf', STATS = 10,REPLACE
时间: 2024-10-11 18:09:06