我想在Date的基础上删除表中的数据。 [英] I want to delete data from table on the basis of Date.

查看:153
本文介绍了我想在Date的基础上删除表中的数据。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从用户界面中选择日期,按钮点击数据将被删除,这将是比选定日期早两个月的日期数据。

Select date from UI and on button click data will be deleted which will be two months prior date data than selected date.

推荐答案

你真的要删除吗?数据库中的数据?什么消失了永远消失,没有回收站。阅读:我们应该删除数据吗? -a-database [ ^ ]

保留的另一个原因可能是审计目的。
Do you really want to delete data from database? What gone is forever gone, no recycle bin. Read this: should-we-ever-delete-data-in-a-database[^]
Another reason to keep could be for audit purpose.


如果你有这个,那就是这样的名为UserInfo的表,其列为RegistrationDate。将RegistrationDate视为datetime列。现在假设它有2014年1月1日到2014年3月31日范围内的数据。



现在如果用户选择3月1日,那么从3月1日起2个月之前的数据将被删除通过以下查询

This will be like this, if you have table called UserInfo with column RegistrationDate. Consider 'RegistrationDate' as datetime column. Now suppose it has data for range Jan 1st 2014 to March 31st 2014.

Now if user select 1st March , the data older then 2 months from 1st March will be deleted by below query
Delete from UserInfo Where RegistrationDate <= dateadd(month, -2, getdate())


这篇关于我想在Date的基础上删除表中的数据。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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