I have never needed to run the
ShrinkDatabase
command but I have other BAT files that I use for scheduled maintenance of my database. Below is an example using your SQL commands.
1. Create
C:\BAT\SHRINKDB.BAT
containing these statements:
cd C:\Program Files\Microsoft SQL Server\110\Tools\Binn
SQLCMD -S YOURCOMPUTERNAME\SQLEXPRESS -E -w 166 -e -i C:\BAT\ShrinkDB.sql -o C:\BAT\ShrinkDB.log
After execution, C:\BAT\ShrinkDB.log will contain the output of SQLCMD.
2. Create
C:\BAT\SHRINKDB.SQL
containing the SQL commands:
ALTER database dbName SET RECOVERY simple
GO
DBCC shrinkdatabase (dbName)
GO
3. Use Windows Task Scheduler to schedule
C:\BAT\ShrinkDB.bat