首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

怎样查询 数据库 某段 时间 某个表的 数据,该怎么解决

2012-06-15 
怎样查询数据库 某段 时间 某个表的数据如题![解决办法]删除的数据怎么查回来?历史表?[解决办法]SQL code-

怎样查询 数据库 某段 时间 某个表的 数据
如题!

[解决办法]
删除的数据怎么查回来?历史表?
[解决办法]

SQL code
---->>TravyLee生成测试数据:if OBJECT_ID('test')is not nulldrop table testgocreate table test(    id int,  value varchar(5),  dates datetime  )goinsert testselect 1,'aaa','2012-05-31 21:31:28' union allselect 2,'bbb','2012-05-28 21:31:28' union allselect 3,'ccc','2012-05-27 21:31:28' union allselect 4,'ddd','2012-05-26 21:31:28' union allselect 5,'eee','2012-05-25 21:31:28'goif OBJECT_ID('tbl')is not nulldrop table tblgocreate table tbl(    id int,  value varchar(5),  dates datetime  )go--创建触发器,当删除数据是把删除的数据插入到删除数据表tbl:if OBJECT_ID('tri_test')is not nulldrop trigger tri_testgocreate trigger tri_test on testfor deleteasinsert tblselect * from deletedgo--测试:delete from test where dates in('2012-05-31 21:31:28','2012-05-27 21:31:28')goselect * from test where dates between '2012-05-27 21:31:28' and '2012-05-31 21:31:28'union allselect * from tbl where dates between '2012-05-27 21:31:28' and '2012-05-31 21:31:28'order by id/*id    value    dates1    aaa    2012-05-31 21:31:28.0002    bbb    2012-05-28 21:31:28.0003    ccc    2012-05-27 21:31:28.000*/--想直接从一张表中查询出来是不大现实的
[解决办法]
改状态,is_deleted=0 删除是等于1

热点排行
Bad Request.