转载:Restore SQL Server database and overwrite existing database
转载自: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的更多相关文章
- C#面试题(转载) SQL Server 数据库基础笔记分享(下) SQL Server 数据库基础笔记分享(上) Asp.Net MVC4中的全局过滤器 C#语法——泛型的多种应用
C#面试题(转载) 原文地址:100道C#面试题(.net开发人员必备) https://blog.csdn.net/u013519551/article/details/51220841 1. . ...
- [转载]在SQL Server 中,如何实现DBF文件和SQL Server表之间的导入或者导出?
原来使用SQL Server 2000数据库,通过DTS工具很方便地在SQL Server和DBF文件之间进行数据的导入和导出,现在安装了SQL Server2005之后,发现其提供的“SQL Ser ...
- Linked Server for SQL Server 2012(x64) to Oracle Database 12c(x64)
因为把两台数据库装了同一台机机器上,所以没有安装oracle Client的部分,Oracle部分使用netca创建的Net Service Name,使用tnsping以及登入方式的确认用户权限的以 ...
- 转载:SQL Server高效 -- 设计(ITPUT 讨论汇总
http://blog.csdn.net/zjcxc/article/details/8979756 认为在设计SQL Server对象时,主要会考虑哪些因素来避免出现性能问题? 讨论汇总——总体设计 ...
- 【转载】Sql Server参数化查询之where in和like实现详解
文章导读 拼SQL实现where in查询 使用CHARINDEX或like实现where in 参数化 使用exec动态执行SQl实现where in 参数化 为每一个参数生成一个参数实现where ...
- [转载]使用SQL Server 2008的事务日志传送功能备份数据库(logshiping)
http://www.cnblogs.com/benbenkoala/archive/2009/03/11/1407793.html 引言:SQL Server的事务日志传送备份是仅次于镜像的高可靠性 ...
- 【转载】SQL Server 2012将数据导出为脚本详细图解
前记: 从SQL SERVER 2008开始,我们就可以很方便的导出数据脚本,而无需再借助存储过程,但是SQL Server 2012和SQL Server 2008的导出脚本的过程还有一点细微的差别 ...
- 【转载】SQL Server 2008 R2 使用的端口解析
转载博客:http://www.cnblogs.com/studyzy/archive/2009/11/30/1614139.html SQL Server在安装到服务器上后,出于服务器安全的需要,所 ...
- 【转载】SQL Server 2008 r2 中 SQL语句中单引号转义
sql server有两个转义符. 默认情况下, 单引号'是字符串的边界符, 如果在字符串中包含单引号', 则必须使用两个单引号', 第1个单引号'就是转义符.
随机推荐
- SQL Server 中的三种分页方式
USE tempdb GO SET NOCOUNT ON --创建表结构 IF OBJECT_ID(N'ClassB', N'U') IS NOT NULL DROP TABLE ClassB GO ...
- XML学习笔记(2)--dom4j操作XML
1. 介绍(四种方式的比较这部分转载自:http://www.blogjava.net/xcp/archive/2010/02/12/312617.html) 1)DOM(JAXP Crimson解析 ...
- UVALive 7281 Saint John Festival (凸包+O(logn)判断点在凸多边形内)
Saint John Festival 题目链接: http://acm.hust.edu.cn/vjudge/contest/127406#problem/J Description Porto's ...
- POJ Wormholes (SPFA)
http://poj.org/problem?id=3259 Description While exploring his many farms, Farmer John has discovere ...
- sping配置文件中引入properties文件方式
<!-- 用于引入 jdbc有配置文件参数 可以使用PropertyPlaceholderConfigurer 或者PropertyOverrideConfigurer --> <b ...
- POJ 1088 滑雪 (记忆化搜索)
题目链接:http://poj.org/problem?id=1088 题意很好懂,就是让你求一个最长下降路线的长度. dp[i][j]记录的是i j这个位置的最优的长度,然后转移方程是dp[i][j ...
- Simple guide to Java Message Service (JMS) using ActiveMQ
JMS let’s you send messages containing for example a String, array of bytes or a serializable Java o ...
- 数据库连接字符串ConnectionString 中的关键字值释义
ConnectionString 类似于 OLE DB 连接字符串,但并不相同.与 OLE DB 或 ADO不同,如果“Persist Security Info ”值设置为false(默认值),则返 ...
- Linux学习笔记--(1)
今天用Linux 的 test 命令,发现了一个有趣的现象: 打入 " test "abc"="abc" ;echo $? " 后,结果应该 ...
- RFID与射频卡电器特性
电气特性: 容量为8K位EEPrOM: ● 分为16个扇区,每个扇区为4块,每块16个字节,以块为存取单位: ● 每个扇区有独立的一组密码及访问控制: ● 每张卡有唯一序列号,为32位: ● 具有防冲 ...