MS SQL 2008R2 Express,我有数据库 - 一个带有行的表。当 db 大小变成大约 10gb 时,我需要清理这张表中最旧的一周(我不知道日期)。你能帮我写脚本吗?谢谢。
UPD1。
有 DateAndTime 列,所以我在 VBA 中进行这样的查询:
strSQL = "SELECT DateAndTime
,TagName
,Val
,SetPoint
,Limit_H
,Limit_L
,Result
FROM dbo.Statistic
WHERE DateAndTime BETWEEN CAST('" & TimeBegin & "' AS datetime) AND CAST( '" & TimeEnd & " ' AS datetime)
Order By DateAndTime desc , (CASE WHEN ISNUMERIC(TagName)=1 THEN CAST(CAST(TagName AS float) AS INT)END ) desc"
请您参考如下方法:
那这个呢 -
DELETE YOUR_TABLE
WHERE DATE_COL BETWEEN (SELECT MIN(DATE) FROM YOUR_TABLE) AND (SELECT MIN(DATE) FROM YOUR_TABLE) + 7