在指定的日期删除记录ASP.NET MVC [英] Delete records when on specified date ASP.NET MVC

查看:49
本文介绍了在指定的日期删除记录ASP.NET MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想问一问,当当前日期和时间达到记录删除日期时间时,如何自动从数据库中删除项目?

I want to ask how I could delete item from the database automatically when current date and time reaches record delete datetime stored in database?

推荐答案

由于已使用ASP.NET MVC和Entity Framework对此进行了标记,因此我不确定是否可以访问基础数据库服务器。但是,如果这样做,ASP.NET应用程序不是最佳选择。而是在后端服务器上设置一个SQL Server Agent作业,该作业可以指定的时间间隔运行,并运行 Delete 查询。

Since you've tagged this with ASP.NET MVC and Entity Framework, I'm not sure if you have access to the underlying database server or not. But if you do, your ASP.NET application isn't the best place to do this. Instead, set up a SQL Server Agent job on the backend server that can run at a specified interval and run a DELETE query.

创建如下存储过程:

CREATE PROCEDURE dbo.DeleteOnSchedule
AS
BEGIN
  DELETE [dbo].[Table]
  WHERE [DateTimeToDelete] <= CURRENT_TIMESTAMP;
END

然后按计划运行该过程。

Then run that procedure on a scheduled basis.

这篇关于在指定的日期删除记录ASP.NET MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆