一键清理SQL Server数据库历史记录sql脚本,并可以自定义清除多久之前的记录。
脚本内容:
DECLARE @CurrentDateTime DATETIME SET @CurrentDateTime = GETDATE() -- 删除超过24小时的记录 DELETE FROM RYRecordDB.dbo.RecordRoomScore WHERE DATEDIFF(HOUR, RecordTime, @CurrentDateTime) > 24 DELETE FROM RYRecordDB.dbo.RecordRoomGame WHERE DATEDIFF(HOUR, RecordTime, @CurrentDateTime) > 24 DELETE FROM RYRecordDB.dbo.RecordRoomCard WHERE DATEDIFF(HOUR, RecordTime, @CurrentDateTime) > 24 DELETE FROM RYRecordDB.dbo.RecordRoom WHERE DATEDIFF(HOUR, RecordTime, @CurrentDateTime) > 24
脚本作用:
执行脚本,清除数据库RYRecordDB四个表RecordRoomScore、RecordRoomGame、RecordRoomCard和RecordRoom,里面所有超过24小时的记录,只保留最新24小时内的数据,以执行脚本的时间开始计算24小时。
发表评论