SQL server restores a database through Logs

Source: Internet
Author: User

-- Create Test Database

Create database Test

On primary

(

Name = 'test _ data. mdf ',

Filename = 'd: Test_data.mdf'

)

Log on

(

Name = 'test _ data. ldf ',

Filename = 'd: Test_data.ldf'

)

-- Create a test table

Create table Test. dbo. ta (id int)

Insert into Test. dbo. ta select id from sysobjects

-- Create a backup file

Backup database Test to disk = 'd: Test. bak 'with format

-- Create an NDF File

Alter database Test

Add file

(

Name = 'file ',

Filename = 'd: test. ndf ',

SIZE = 1 MB

)

-- Disable the MSSQL service, delete the NDF file, and enable the MSSQL service. The Test database is suspected!

-- Restore Data suspect

-- First back up the log file

Backup log Test to disk = 'd: Test_log.bak 'with format, no_truncate

-- Use the backup file of the file group to restore the damaged file

Restore database Test from disk = 'd: Test. bak 'with Norecovery

-- Restore log files

Restore Log Test from disk = 'd: Test_log.bak 'with RECOVERY

-- TipS

-- If an ndf file has been created, use the following statement to restore the log file:

-- Only with RECOVERY --> WITH REPLACE

Restore Log Test from disk = 'd: Test_log.bak 'WITH REPLACE

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.