转载自: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".

转载:Restore SQL Server database and overwrite existing database的更多相关文章

  1. C#面试题(转载) SQL Server 数据库基础笔记分享(下) SQL Server 数据库基础笔记分享(上) Asp.Net MVC4中的全局过滤器 C#语法——泛型的多种应用

    C#面试题(转载) 原文地址:100道C#面试题(.net开发人员必备)  https://blog.csdn.net/u013519551/article/details/51220841 1. . ...

  2. [转载]在SQL Server 中,如何实现DBF文件和SQL Server表之间的导入或者导出?

    原来使用SQL Server 2000数据库,通过DTS工具很方便地在SQL Server和DBF文件之间进行数据的导入和导出,现在安装了SQL Server2005之后,发现其提供的“SQL Ser ...

  3. Linked Server for SQL Server 2012(x64) to Oracle Database 12c(x64)

    因为把两台数据库装了同一台机机器上,所以没有安装oracle Client的部分,Oracle部分使用netca创建的Net Service Name,使用tnsping以及登入方式的确认用户权限的以 ...

  4. 转载:SQL Server高效 -- 设计(ITPUT 讨论汇总

    http://blog.csdn.net/zjcxc/article/details/8979756 认为在设计SQL Server对象时,主要会考虑哪些因素来避免出现性能问题? 讨论汇总——总体设计 ...

  5. 【转载】Sql Server参数化查询之where in和like实现详解

    文章导读 拼SQL实现where in查询 使用CHARINDEX或like实现where in 参数化 使用exec动态执行SQl实现where in 参数化 为每一个参数生成一个参数实现where ...

  6. [转载]使用SQL Server 2008的事务日志传送功能备份数据库(logshiping)

    http://www.cnblogs.com/benbenkoala/archive/2009/03/11/1407793.html 引言:SQL Server的事务日志传送备份是仅次于镜像的高可靠性 ...

  7. 【转载】SQL Server 2012将数据导出为脚本详细图解

    前记: 从SQL SERVER 2008开始,我们就可以很方便的导出数据脚本,而无需再借助存储过程,但是SQL Server 2012和SQL Server 2008的导出脚本的过程还有一点细微的差别 ...

  8. 【转载】SQL Server 2008 R2 使用的端口解析

    转载博客:http://www.cnblogs.com/studyzy/archive/2009/11/30/1614139.html SQL Server在安装到服务器上后,出于服务器安全的需要,所 ...

  9. 【转载】SQL Server 2008 r2 中 SQL语句中单引号转义

    sql server有两个转义符. 默认情况下, 单引号'是字符串的边界符, 如果在字符串中包含单引号', 则必须使用两个单引号', 第1个单引号'就是转义符.

随机推荐

  1. 编译arm64错误记录

    响应2月底appstore 64位APP的上线要求,开始编译IOS arm64版本引擎库.编译arm64遇到一些问题,在此记录. 1. 数据类型的错误 __int64 相关,提示error: expe ...

  2. 第二百八十六天 how can I 坚持

    bug不断啊,头疼. 今天早上到的倒是挺早. 中午吃的黄焖鸡,晚上加了会班. 勇江的鱼都死了,杨建的还剩3条,晚上到家都快十点了,还洗了衣服,没捞出来呢, 希望可以请下来假吧. 晾上衣服睡觉.

  3. jvm所占空间的配置

    http://www.cnblogs.com/mingforyou/archive/2012/03/03/2378143.html

  4. 软件工程——PairProject

    结对编程组员: 马辰     11061178 柴泽华  11061153 1)    照至少一张照片, 展现两人在一起合作编程的情况. 结对编程的优点 1)在编程过程中,任何一段代码都不断地复审,同 ...

  5. JDBC学习笔记(6)——获取自动生成的主键值&处理Blob&数据库事务处理

    获取数据库自动生成的主键 [孤立的技术是没有价值的],我们这里只是为了了解具体的实现步骤:我们在插入数据的时候,经常会需要获取我们插入的这一行数据对应的主键值. 具体的代码实现: /** * 获取数据 ...

  6. Spring Auto proxy creator example

    In last Spring AOP examples – advice, pointcut and advisor, you have to manually create a proxy bean ...

  7. poj 1543 Perfect Cubes(注意剪枝)

    Perfect Cubes Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 14901   Accepted: 7804 De ...

  8. MongoDB的安装配置

    1,下载: http://www.mongodb.org/downloads 2.4.5版:http://www.mongodb.org/dr/fastdl.mongodb.org/linux/mon ...

  9. opencv 矩阵的相似性对比 (图片之间比较)

    测试图片:     code: #include <opencv\cv.h> #include <opencv\highgui.h> #include <opencv\c ...

  10. Android访问WebService的两种方法

    首先解释一下WebService:WebService是一种基于SOAP协议的远程调用标准.通过WebService可以将不同操作系统平台,不同语言.不同技术整合到一起.详细见:http://baik ...