可记录历史数据的表单设计
来源:互联网 发布:php开发工程师要求 编辑:程序博客网 时间:2024/05/18 04:00
格式
Record
Data
Created
Replaced
12
…
2
…
2
…
3
…
3
…
2
…
3
…
4
…
每次修改都往表中增加一行。
修改记录:写当前的记录Replaced时间戳,插入新记录Created时间戳。
取得记录:直接拿到Replaced时间为null的记录。
删除记录:写当前的记录Replaced时间戳。
取得删除的Records:
IF EXISTS (SELECT * FROM sysobjects WHERE name='#temp')
BEGIN
drop table #temp
END
GO
select RowNum = IDENTITY(int, 1, 1), id=([db_id]+0), contact_id, dateReplaced into #temp from Contact where contact_id in
(
select distinct contact_id from Contact a
where not exists
(
select 1 from Contact
where contact_id=a.contact_id and DateReplaced is null
)
)
order by contact_id, dateReplaced
select id from #temp where RowNum in
(
select max(RowNum) from #temp
group by contact_id
)
drop table #temp
BEGIN
drop table #temp
END
GO
select RowNum = IDENTITY(int, 1, 1), id=([db_id]+0), contact_id, dateReplaced into #temp from Contact where contact_id in
(
select distinct contact_id from Contact a
where not exists
(
select 1 from Contact
where contact_id=a.contact_id and DateReplaced is null
)
)
order by contact_id, dateReplaced
select id from #temp where RowNum in
(
select max(RowNum) from #temp
group by contact_id
)
drop table #temp
其中关键部分是删除的记录号
select distinct contact_id from Contact a
where not exists
(
select 1 from Contact
where contact_id=a.contact_id and DateReplaced is null
)
总结
其他还有很多记录历史数据的方法。这只是其中之一。首推trigger+backup表。对于结构比较固定的表,推荐采用backup表。而此文介绍的方法对于维护要求很低。相对来说,在建立Stored Procedure上要多花很多时间来测试。可谓各有所长。
- 可记录历史数据的表单设计
- 网页设计前端的表单记录
- 中国卫星历史数据分析记录
- 数据库表设计系列:历史数据问题之单、多记录变更
- 数据库存储历史数据设计注意事项
- 历史数据的保存
- 股票历史数据的获取
- 股票历史数据的获取
- 工作流实施中FlowPortal.net对于表单设计易用性和可扩展性的考虑
- 驰骋开源工作流ccflow可扫描二维码的表单设计
- 对于历史数据问题的思考
- MT4-历史数据中心的下载
- 清理Oracle历史数据的准备工作
- Python 股票历史数据的获取
- 可扩展的设计
- HTML表单的设计
- 复杂表单的设计
- 表单设计的思考
- 专家解读"劳动合同法":企业员工均有误读
- 关于Java Servlet的Filter 技术
- 蜘蛛/爬虫程序的多线程控制(C#语言)
- Sizeof 与 Strlen 的区别与联系
- 什么是中间件?
- 可记录历史数据的表单设计
- XP系统网络不能互访七大解决之道
- DataBinder.Eval用法范例
- 北京伊莎贝尔服装公司信息化方案
- Visual C++ 头文件互相包含的解决方案
- 开始学习PHP
- 搜索引擎重复网页发现技术分析
- C 语言吧 · 问题资料大全
- ASCII 码对照表