转载:Restore SQL Server database and overwrite existing database
2015-11-04 14:01
337 查看
转载自:https://www.mssqltips.com/sqlservertutorial/121/restore-sql-server-database-and-overwrite-existing-database/
Restore SQL Server database and overwrite existing database
(RESTORE ... WITH REPLACE)Overview
The RESTORE ... WITH REPLACE option allows you to overwrite an existing database when doing a restore. In some cases when you try to do a restore you may get an error that says "The tail of the log for the database .. has not been backed up".Explanation
The RESTORE ... WITH REPLACE allows you to write over an existing database when doing a restore without first backing up the tail of the transaction log. The WITH REPLACE basically tells SQL Server to just throw out any active contents in the transaction log and move forward with the restore.If you try to restore using T-SQL commands you will get this error message:
Msg 3159, Level 16, State 1, Line 1
The tail of the log for the database "AdventureWorks" has not been backed up. Use BACKUP LOG WITH NORECOVERY to backup the log if it contains work you do not want to lose. Use the WITH REPLACE or WITH STOPAT clause of the RESTORE statement to just overwrite the contents of the log.
Msg 3013, Level 16, State 1, Line 1
RESTORE DATABASE is terminating abnormally.
If you try to restore using SQL Server Management Studio you will see this error message:
T-SQL
Restore full backup using WITH REPLACE
The command below will restore the database and disregard any active data in the current transaction log.
RESTORE DATABASE AdventureWorks FROM DISK = 'C:\AdventureWorks.BAK' WITH REPLACE GO
SQL Server Management Studio
To restore using SSMS do the following, on the options page for the restore select "Overwrite the existing database".
相关文章推荐
- Mysql触发器
- redis memcache 比较
- MongoDB开发学习(1)开天辟地,经典入门
- SQL Server中的事务日志管理(6/9):大容量日志恢复模式里的日志管理
- 数据库事务以及隔离级别和可能出现的问题
- MySQL:MySQL基本入门
- MySQL事务autocommit自动提交
- 缓存应用--Memcached分布式缓存简介
- 数据库SQL中Like的用法总结
- 数据库课堂笔记
- PostgreSQL中使用动态SQL-实现自动按时间创建表分区
- mysql性能测试及不同版本的比较
- Oracle笔记
- mysql读写性能测试
- MySQL数据库引擎介绍、区别、创建和性能测试的深入分析
- 一些经典===>>用SQL语句操作数据
- SQL 性能调优
- SQLServer 使用sp_repldone标识所有未分发的事务为已分发
- Mysql命令大全
- SQLServer ucMSrepl_transactions和ucMSrepl_commands插入重复键