Batch file to shrink the log file of a SQL server express database

Hi Experts,

We are running a server with SQL server express which has the recovery model set to simple.
Is it possible to shrink the log file from a batch file?. Id like setup a schedule to shrink the log file within task scheduler since i believe our version of MS SQL server express doesnt have the management jobs to setup tasks that the full versions of SQL server have.

Thanks
sherlock1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Aneesh RetnakaranDatabase AdministratorCommented:
You can create a SQL File to that contains the DBCC SHRINKFILE (N'Your log file' , 128) and save it as  "Shrinkfile.sql"
Thru task scheduler call this job using the cmd statement
SQLCMD -S . -i "c:\path\shrinkFile.sql"

more information on SQLCMD can be seen here
https://docs.microsoft.com/en-us/sql/tools/sqlcmd-utility?view=sql-server-2017
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Vitor MontalvãoMSSQL Senior EngineerCommented:
If the database is in Simple Recovery mode I wouldn't expect the transaction log to grow much. I would rather investigate why it's growing a lot instead of just shrinking without knowing the root cause of the issue. It's like restarting a computer just because sometimes it hangs. It will keep hanging until you solve the main issue like the database transaction log will continue growing until you solve the issue as well.
0
sherlock1Author Commented:
that's  great, thanks for this.
Yes will try to find out the root cause of whats causing the log file to grow so much
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
SQL

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.