Ways to delete a database log file

Source: Internet
Author: User

Original: How to delete a database log file

You used to have SQL, the database reported that the transaction log was full, and then performed an error. Then tangled in how to delete the database log, tinkering half a day, now provides two ways to delete log files, hope to help you !

Read Catalogue

    • Method One: manual operation
    • Method Two: Stored procedure instead of manual operation
    • Sample Stored Procedure Download
Back to top method one: manual operation

1. Right-click Properties---recovery mode--switch from complete to simple

2. Database-> Right-click Task---file----from completion switch to simple--file type, log--shrink file to

Back to top method two: Stored procedure instead of manual operation

  

    --How many m the log file shrinks to    DECLARE @DBLogSise  as INT    SET @DBLogSise=0    --Query the name of the log file for the database    DECLARE @strDBName  as NVARCHAR( -)    DECLARE @strLogName  as NVARCHAR( -)    DECLARE @strSQL  as VARCHAR( +)        SELECT         @strLogName=B.name,@strDBName=A.name fromMaster.sys.databases asAINNER JOINSys.master_files asB ona.database_id=b.database_idWHEREa.database_id=db_id()             SET @strSQL='--Set the database recovery mode to simple ALTER ['+@strDBName+'] SET RECOVERY simple; --Shrink log file DBCC shrinkfile (" "+@strLogName+" " , '+CONVERT(VARCHAR( -),@DBLogSise)+'); --Restore the database restore mode to full ALTER databases ['+@strDBName+'] SET RECOVERY full'    exec(@strSQL)

1. Execute the above stored procedure in the database

2. Then execute EXEC dbo.usp_p_deldblog @DBLogSise = 0 (shrink to how many m)

  

Back to top sample stored procedure download

Usp_p_deldblog.sql

  

Next article will bring you: Attach a database method without a log file

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.