ashish1512
ashish1512

Reputation: 483

delete all rows every half hour in MsSQL, ASP.NET

I have hosted a web app on GoDaddy made using ASP.NET and SQL Server Express(MsSQL). I want the web app to delete all rows in the table every half hour automatically. Like implementing a script or job or something. How should I do it? Please help.

Upvotes: 3

Views: 89

Answers (1)

StackUser
StackUser

Reputation: 5398

As per your statement you are using SQL Server Express edition. I think creating a SQL Server Agent Job is not possible in Express edition however you can achieve it through windows task scheduler.

Follow this.

Create a SQL file, add all your SQL statements then save it as MyScript.sql

--------------
Truncate table Targettablename
...
...
--------------

Create a batch script named Execute.bat with following code

--------------
sqlcmd -S <ServerName> -U <UserName> -P <Password> -d <TargetDBName> -i MyScript.sql -o MyOutput.txt
-------------

Note: Mention the valid ServerName, Username, Password and TargetDBname in this batch script

Schedule this batch file using windows task scheduler. You can google it to know how to schedule windows task scheduler.

Upvotes: 5

Related Questions