1. SQL2000 Database:
Executing this script does not simply use Sqlscript.sql, after you back up the database, open SQL Query Analyzer (MSSQL2000) or
VS Management (MSSQL2003 above) new query, fill in the log too large database name (for example: MIS), execute the SQL statement;
--1. Emptying the log
DECLARE @DBName VARCHAR (64)
SET @DBName = ' mis '
DUMP TRANSACTION @DBName with no_log
--2. truncating the transaction log
BACKUP LOG @DBName with no_log
--3. Shrinking a Database
DBCC Shrinkdatabase (@DBName)
GO
SQL2005 or later:
The script is as follows:
*****************************************************************************
Use [master]
GO
ALTER DATABASE Mis_gxzl SET RECOVERY simple with no_wait
GO
ALTER DATABASE Mis_gxzl SET RECOVERY Simple--Easy mode
GO
Use Mis_gxzl
GO
DBCC shrinkfile (N ' Mis_log ', truncateonly)
GO
--Here's dnname_log if you don't know what the name is in sys.database_files, you can query it with the following annotated statement
Use Mis_gxzl
GO
SELECT file_id, name from Sys.database_files;
GO
Use [master]
GO
ALTER DATABASE Mis_gxzl SET RECOVERY full with no_wait
GO
ALTER DATABASE Mis_gxzl SET RECOVERY Full--Revert to complete mode
GO
********************************************************************************
Attention:
1, please copy two lines of "*" in the middle of the content;
2, need to replace two parameters:
MIS_GXZL: The database name of the SQL2008 that needs to be shrunk;
DBCC shrinkfile (N ' Mis_log ', one, truncateonly) in Mis_log, this parameter needs to be based on
Use Mis_gxzl
GO
SELECT file_id, name from Sys.database_files;
GO
To query out the database corresponding to the log file's physical file name;
2, after the log manual cleanup, under the SQL Management Studio database name right-click Properties, under the Database properties check the option, under the automatic automatic contraction under the option of false change to true;
3. When setting up a database maintenance plan, select the Maintenance Plan task to backup and shrink the database;
Database log too large solution