转载自: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. 【Spark学习】Apache Spark作业调度机制

    Spark版本:1.1.1 本文系从官方文档翻译而来,转载请尊重译者的工作,注明以下链接: http://www.cnblogs.com/zhangningbo/p/4135905.html 目录 概 ...

  2. Himi的base64代码

    // // DataHimi.cpp // Oh!MonsterMR // // Created by Himi on 12-3-8. // Copyright (c) 2012年 Augustimp ...

  3. Sql CLR

    using System;using System.Data;using System.Data.SqlClient;using System.Data.SqlTypes;using Microsof ...

  4. Unity3D之UGUI学习笔记(三):EventSystem

    在UGUI中,EventSystem实现了所有关于交互方面的功能,和NGUI不一样的地方是,我们终于可以摆脱添加Box Collider了! 下面我们来学习一下. 对于按钮来说,直接有onClick的 ...

  5. memcached构建集群分析之一

    memcached本身是不支持集群的,集群所关注的容灾.容错.宕机恢复机制统统都没有,实战中需要自己实现容灾机制. memcached集群相比memcached的优势: 巨量数据分布到集群的多台应用主 ...

  6. js字符串常用判断方法

    转自:http://blog.sina.com.cn/s/blog_6819fa800100j5t6.html 一.方法介绍 function obj$(id)                     ...

  7. Hadoop 2.0+YARN启动脚本分析与实战经验

    start-all.sh脚本现在已经废弃,推荐使用start-dfs.sh和start-yarn.sh分别启动HDFS和YARN. 在新一代的Hadoop里面HDFS称为了统一存储的平台,而YARN成 ...

  8. Cocos2d-x——支持多触点

    1:在AppController的didFinishLaunchingWithOptions中,加入 [__glView setMultipleTouchEnabled:YES]; 2:在CCLaye ...

  9. 【WinForm】C# 发送Email

    发送Email  的条件 1.SmtpClient SMTP 协议    即 Host 处理事务的主机或IP地址     //smtp.163.com      UseDefaultCredentia ...

  10. [置顶] SNMP协议详解<二>

    上一篇文章讲解了SNMP的基本架构,本篇文章将重点分析SNMP报文,并对不同版本(SNMPv1.v2c.v3)进行区别! 四.SNMP协议数据单元 在SNMP管理中,管理站(NMS)和代理(Agent ...