简体   繁体   中英

How to schedule a database task?

Background: I created an application that measures a weight from a scale and saves the information in MS SQL server database.

In the database, I want to save a record for the actual weight for every day as historical, and I don't know what I have to use to accomplish this task.

Can a trigger in SQL Server do it??

You don't need to try and hack this with a trigger. In SQL Server this type of feature (scheduled execution) is easily managed with a SQL Server Job . You would just create a SQL Server job that runs once a day and executes whatever T-SQL you need to meet the biz logic requirement.

So you don't actually need to code anything else. Just configure a job and set its schedule. You do not need another application. SQL Server already manages scheduled execution with SQL Agent.

Do note that the SQL Server Jobs feature is not available with SQL Server Express editions.

Simple approach: use Windows Scheduler .

If this approach is too simple then create windows service and use Quartz.NET in your implementation to have trigger functionality.

If you need to run a scheduled task/cron job in a shared hosting environment, you'll find a list of free web cron job providers here:ASP.NET: Free scheduling of your tasks (Cron jobs)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM