SQL Server restores database through log

Source: Internet
Author: User
Tags mssql create database

--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 a NDF file

ALTER DATABASE Test

Add File

(

Name= ' file ',

Filename= ' D:test.ndf ',

SIZE = 1MB

)

--Shut down the MSSQL service, then delete the NDF file and then open the MSSQL service, the test database is suspect now!

--Recovery data suspect

--Back up the log files first

Backup log Test to disk= ' D:test_log.bak ' with format,no_truncate

--Recover corrupted files with file group backup files

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

--Recovery log files

Restore Log Test from disk= ' D:test_log.bak ' with RECOVERY

--tips

If the NDF file has been established, then restore the log file with the following words

--Only the 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.