当前位置: 代码迷 >> Sql Server >> 怎样查询 数据库 某段 时间 某个表的 数据,该怎么解决
  详细解决方案

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

热度:535   发布时间:2016-04-27 12:21:46.0
怎样查询 数据库 某段 时间 某个表的 数据
如题!

------解决方案--------------------
删除的数据怎么查回来?历史表?
------解决方案--------------------
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
  相关解决方案