1

How I can delete data from SQL Server table using batch.

I'm using SQL Server 2008 R2.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
HaOx
  • 1,839
  • 6
  • 26
  • 36

1 Answers1

5

Do you mean configuring your sql script as batch job? if yes, then write your sql query in a script like

Filename: sqldelete.sql

delete from my_table where <some condition>;
GO

Create a batch file .bat and call your sql script in there like

sqlcmd -s <server name> -d <db name> -i sqldelete.sql

For more options on sqlcmd: run command sqlcmd /? in command prompt

Configure this .bat file to run in schedule as per your need

If you want to know how to schedule task in windows task scheduler then take a look @ http://support.microsoft.com/kb/308569 (This is for WINXP).

Rahul
  • 76,197
  • 13
  • 71
  • 125