Run SQL queries in a batch file

I recently had to delete records from a table regularly, every 10 minutes. I first obviously thought of setting up  a SQL Agent Job, easy!!!

Now here is my problem, I am using SQL Server Express Edition, which doesn’t come with SQL Server Agent features. So the SQL way wasn’t an option. I then realised that I could setup a scheduled task in Windows (XP) that would run a batch file every 10 minutes, job done!

Here is an example of the batch file:

@ECHO OFF
cd C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Binn
SQLCMD -SserverName\instanceName -Uusername -Ppassword -Q"delete from DatabaseName.dbo.TableToDelete"
@ECHO OFF

Save it as something like Query.bat and call it via a scheduled task.

Leave a Reply

Spam Protection by WP-SpamFree

RedGate SQL-Compare
RedGate SQL-Compare
RedGate Data Compare
RedGate Data Compare
Quest Spotlight
Quest Spotlight
Quest Performance Analysis
Quest Performance Analysis