问题描述
我正在开发一个应用程序,其中我有3列(id,name和date)的表。
现在在日期字段中我存储了用户加入的日期,但现在我要删除超过4天的用户记录,从最初的加入日期开始。
我想要这样的东西......
日期字段有条目4/6 / 2013
现在4天后,即2013年8月6日所有具有4/6/2013日期的记录将自动删除...这应该自动完成..让我们说当服务器时间到了凌晨12:00它应该自动发生......我怎样才能做到这一点?
请帮帮我..?
提前致谢。
I am developing an application in which i have table with 3 columns (id, name and date).
Now in date field I am storing date the user joined, but now i want to delete the user records which are over 4 days old, from the original date of joining.
I want something like this...
there is entry on date field 4/6/2013
Now after 4 days i.e. on 8/6/2013 all the records having 4/6/2013 date will be removed autometically... This should be done automatically.. Lets say when the server time gets 12:00AM it should be happen automatically... How can i achieve this?
Please help me out..?
Thanks in advance.
推荐答案
delete from dbo.Table where Date_Column<GETDATE()-4
尝试it.it应该有效..
-Anurag
try it.it should work..
-Anurag
这篇关于在特定时间内自动从数据库中删除数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!