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