SQL Server error Delete table recovery

Source: Internet
Author: User
Tags getdate

SQL Server Full Recovery ModelTo recover the deleted tables by mistake, PrecisionRecovery

1. Find the deleted table name (no schema, can find the schema sharing), object_id, table database, delete people, delete time, etc.

declare  @database_name  varchar, @type  varchar (2), @pass_hours  int,select  @database _name= ' AdventureWorks2014 ', @pass_hours =-48declare  @file_path  sql_variantselect  @file_path =value  from fn_trace_getinfo (0)  where property=2 and traceid=1select max (GT. HostName)  as  ' Loginhostname ', max (GT. ApplicationName)  as  ' ApplicationName ', max (GT. LoginName)  as  ' LoginName ', min (GT. StartTime)  as  ' Minstarttime ', max (GT. StartTime)  as  ' Maxstarttime ', GT. Objectid,max (GT. ServerName)  as  ' DbServerName ', max (GT. ObjectName)  as  ' ObjectName ', max (GT. DatabaseName)  as  ' DatabaseName ', Max (sv.subclass_name)  as  ' Subclass_name ', Max (e.name)   as  ' Operationtype ' from fn_trace_gettable (CONVERT (varchar), @file_path),  default)  gt  left join sys.trace_subclass_values sv on gt.[eventclass] = sv. [Trace_event_iD] and sv. [subclass_value] = gt.[objecttype] inner join sys.trace_events e on  Gt.[eventclass] = e.[trace_event_id] inner join sys.trace_categories c on  e.[category_id] = c.[category_id] where starttime>=dateadd (HOUR, @pass_hours, GETDATE ())  and starttime<=getdate () and [eventclass]=47 --drop talbe/indexand  [email protected]_nameand subclass_name= ' U ' group by gt. ObjectID

2. Determine which log file the relevant information is logged on by deleting the time

SELECT * from msdb.dbo.backupmediafamily where media_set_id= (select top 1 media_set_id from Msdb.dbo.backupset where [emai L Protected]_nameand backup_finish_date>[email protected]_start_timeand type= ' l ' ORDER by Backup_finish_date)

3. Extracting LSN-related information from a log file

declare  @lockinfo  varchar (+) set  @lockinfo = '%sch_m object%: ' [email protected]+ ':% ', [ Begin time]select [transaction id], ' lsn:0x ' +[current lsn] from fn_dump_dblog   (        null, null, n ' DISK ', 1,  @backupfile ,        default, default, default, default,  Default, default, default,        default, default,  DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT,         DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT,         default, default, default, default, default,  DEFAULT, DEFAULT,        DEFAULT, DEFAULT,  default, default, default,&Nbsp;default, default,        default, default, default , default, default, default, default,         default, default, default, default, default, default, default,         default, default, default, default, default, default,  DEFAULT,        DEFAULT, DEFAULT, DEFAULT,  Default, default, default, default)  as awhere convert (Datetime,[Begin Time] ) Between dateadd (ss,-5, @min_start_time)  and dateadd (ss,5, @max_start_time) and [transaction  name]= ' Dropobj ' and exists (select 1 from fn_dump_dblog  (         null, null, n ' DISK ', 1,  @backupfile,         default, default, default, default, default, default, default,         DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT,  Default,        default, default, default, default,  DEFAULT, DEFAULT, DEFAULT,        DEFAULT,  default, default, default, default, default, default,         default, default, default, default, default, default, default,         DEFAULT, DEFAULT, DEFAULT, DEFAULT,  Default, default, default,        default, default,  DEFAULT, DEFAULT, DEFAULT, DEFAULT, DEFAULT,         default, default, default, default, default, default, default,         default, default, default, default, default, default, default)          where [transaction id]=a.[transaction id] and [ lock information] like  @lockinfo)

4. Recover the required relevant information

5. Mail Display

6. Recovery statement (last executed sentence)

Restore log DBName from disk= ' xxx ' with stopbeforemark= ' xxx '






SQL Server error Delete table recovery

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.