Home Database Mysql Tutorial 记一次SQLServer数据库误删数据找回

记一次SQLServer数据库误删数据找回

Jun 07, 2016 pm 03:40 PM
sqlserver retrieve data database yesterday Mistakenly deleted

昨天 同事在本机清理数据库表时,连接到了生产机,误删了二十几张表,幸好是晚上加班的时候删除的,生产机上当时是一天一备份,还原备份是最后的策略,最关键的还是要找回数据。 生产机环境是server2008 R2、 sqlserver2012,使用delete语句删除的表现在开始

        昨天 同事在本机清理数据库表时,连接到了生产机,误删了二十几张表,幸好是晚上加班的时候删除的,生产机上当时是一天一备份,还原备份是最后的策略,最关键的还是要找回数据。

        生产机环境是server2008 R2、 sqlserver2012,使用delete语句删除的表现在开始还原,还原可参考dudu的这篇文章(链接),其中使用Recovery for SQL Server工具还原,发现还原的数据字段值为demo,所以最后还是用sql命令去还原的,用sql命令,微软官方给的比较明细(链接)。

一、还原需要的条件设置

        使用命令,是通过sqlserver的事务日志以及一个误删除前的数据库的完整备份进行还原,所以在sqlserver2012的维护计划向导中,要建立完整备份,差异备份和事务日志,具体如下记一次SQLServer数据库误删数据找回

以及在数据库属性,选项设置中,设置为完整备份,具体如下图

记一次SQLServer数据库误删数据找回

做好如上两个设置,数据库误删后找回数据就会非常轻松,现在说一下如何还原sqlserver数据到故障点。

二、还原命令

还原主要分为四步走:

1、出现故障后,首先执行备份事务日志命令,这里以AdventureWorks作为数据库名。命令如下:

BACKUP LOG AdventureWorks TO DISK = 'C:\SQLServerBackups\AdventureWorks_transcationlog.bak'  
   WITH NORECOVERY; 
Copy after login

2、从完整备份还原数据

RESTORE  DATABASE [QASupervision] FROM DISK=<span>'M:\Database\OA\AdventureWorks_Fullbackup_2014_03_18_010002_0155764.bak'</span> 
WITH  NORECOVERY, REPLACE 
Copy after login

3、从差异备份还原数据

RESTORE DATABASE [QASupervision] FROM DISK=<span>'M:\Database\OA\AdventureWorks_diffbackup_2014_03_18_020002_0155764.bak'</span> WITH NORECOVERY, REPLACE 
Copy after login

4、从事务日志还原数据,还原到某个时间点之前

DECLARE @dt datetime   
SELECT @dt=DATEADD(HOUR,-16,GETDATE())   
select @dt
RESTORE LOG [QASupervision] FROM DISK='C:\SQLServerBackups\AdventureWorks_transcationlog.bak'  WITH  STOPAT=@dt,RECOVERY
Copy after login

5、还原数据库,如果数据库提示正在还原中,则执行此命令即可。

RESTORE DATABASE AdventureWorks WITH RECOVERY
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

The vitality of super intelligence awakens! But with the arrival of self-updating AI, mothers no longer have to worry about data bottlenecks The vitality of super intelligence awakens! But with the arrival of self-updating AI, mothers no longer have to worry about data bottlenecks Apr 29, 2024 pm 06:55 PM

The vitality of super intelligence awakens! But with the arrival of self-updating AI, mothers no longer have to worry about data bottlenecks

Slow Cellular Data Internet Speeds on iPhone: Fixes Slow Cellular Data Internet Speeds on iPhone: Fixes May 03, 2024 pm 09:01 PM

Slow Cellular Data Internet Speeds on iPhone: Fixes

The U.S. Air Force showcases its first AI fighter jet with high profile! The minister personally conducted the test drive without interfering during the whole process, and 100,000 lines of code were tested for 21 times. The U.S. Air Force showcases its first AI fighter jet with high profile! The minister personally conducted the test drive without interfering during the whole process, and 100,000 lines of code were tested for 21 times. May 07, 2024 pm 05:00 PM

The U.S. Air Force showcases its first AI fighter jet with high profile! The minister personally conducted the test drive without interfering during the whole process, and 100,000 lines of code were tested for 21 times.

What is the difference between mysql and sqlserver syntax What is the difference between mysql and sqlserver syntax Apr 22, 2024 pm 06:33 PM

What is the difference between mysql and sqlserver syntax

Tesla robots work in factories, Musk: The degree of freedom of hands will reach 22 this year! Tesla robots work in factories, Musk: The degree of freedom of hands will reach 22 this year! May 06, 2024 pm 04:13 PM

Tesla robots work in factories, Musk: The degree of freedom of hands will reach 22 this year!

2024 QS ranking released! Computer science MIT dominates the list, Tsinghua University is 11th, Peking University is 15th 2024 QS ranking released! Computer science MIT dominates the list, Tsinghua University is 11th, Peking University is 15th Apr 18, 2024 pm 09:04 PM

2024 QS ranking released! Computer science MIT dominates the list, Tsinghua University is 11th, Peking University is 15th

Open-Sora comprehensive open source upgrade: supports 16s video generation and 720p resolution Open-Sora comprehensive open source upgrade: supports 16s video generation and 720p resolution Apr 25, 2024 pm 02:55 PM

Open-Sora comprehensive open source upgrade: supports 16s video generation and 720p resolution

Single card running Llama 70B is faster than dual card, Microsoft forced FP6 into A100 | Open source Single card running Llama 70B is faster than dual card, Microsoft forced FP6 into A100 | Open source Apr 29, 2024 pm 04:55 PM

Single card running Llama 70B is faster than dual card, Microsoft forced FP6 into A100 | Open source

See all articles