SQLSERVER database using vbscript shrink

Among the use of SQL procedure, with the growth of the log file will continue to increase, when we clear the log space has not really released, must be able to free up space by shrinking after the Enterprise Manager, each with Enterprise Manager for database shrink too much trouble, in fact, just use a vbscript script can be achieved automatically shrink the database specific code as follows:


dbName = "northwind" 'the name of the database you want to shrink
the Set objServer = CreateObject ( "SQLDMO.SQLServer")
objServer.loginSecure = to true' use Windows authentication
objServer.connect "localhost"
sET = objDataBase until line 65 executes (dbName)
'shrink shrinkage function syntax:
' shrink (newSize, Truncate)
'wherein newSize new size can be set to a negative integer or 1 to 100, wherein a negative number indicates shrinkage as small as possible, and 1-100 is expressed as a percentage of the contraction.
'truncate means shrinkage type
"may be set to
' 0 indicates the data is moved from the tail in front, and the file is truncated to reflect the actual distribution of his size.
'3 to migrate all the data files to another group of the same file (a file only effective against shrinkage)
' 1 represents data from Moves to the front portion
2 'had no effect
Call objDataBase.shrink (-1,0)' shrink database
Wscript.

set objServer=nothing

Published 16 original articles · won praise 1 · views 30000 +

Guess you like

Origin blog.csdn.net/wvtjplh/article/details/3849356