日期:2014-05-18  浏览次数:20497 次

sql2000数据丢了
情况是这样的,
一张表中的数据,昨天查有5月1号到5月10号的数据,假如共1000笔,今天查就没
有1000笔了,丢掉了其中某一天的数据,而且是一整天,例如2号全天的没有了,
或是3号的全天没了,而且不定期的出现这样的情况,前一天明明看到数据进来了,到第二天查又丢了。不知道我说清楚了没有,有碰到的或是没碰到朋友帮帮忙找找
原因、分析分析。感谢了!

------解决方案--------------------
看看日志,估计是人为删掉的(比如执行的sql有问题存储过程有问题等),数据库不会动你这一天的数据。
------解决方案--------------------
要不事人为的原因,要不是有存储过程,函数,触发器有问题
------解决方案--------------------
你的那种情况是后面的备份将前面的不固定的某天数据覆盖了
故建议你重新设置你的备份计划
------解决方案--------------------
有没有备份日志

------解决方案--------------------
set nocount on
go

--准备数据库及备份文件

--1
if exists(select * from master..sysdatabases where name= 'dbtest ')
drop database dbtest
go
--初始化时间
exec master..xp_cmdshell 'date 07-27-06 ',no_output--2006-07-27
exec master..xp_cmdshell 'time 12:00:00 ',no_output
waitfor delay '00:00:03 '
go
--12:00:03建测试数据库,并备份该数据库
create database dbtest
go
backup database dbtest to disk= 'c:\dbtest.bak ' with format
go

--2
--改时间
exec master..xp_cmdshell 'date 07-27-06 ',no_output--2006-07-27
exec master..xp_cmdshell 'time 12:01:00 ',no_output
waitfor delay '00:00:03 '
go
--12:01:03建测试表,并添加3条数据
create table dbtest.dbo.t (a int)
go
insert into dbtest.dbo.t (a)
select 1 union all
select 2 union all
select 3
go

--3
--改时间
exec master..xp_cmdshell 'date 07-27-06 ',no_output--2006-07-27
exec master..xp_cmdshell 'time 12:02:00 ',no_output
waitfor delay '00:00:03 '
go
--12:02:03删除表中一条数据
delete from dbtest.dbo.t where a=2
go

--4
--改时间
exec master..xp_cmdshell 'date 07-27-06 ',no_output--2006-07-27
exec master..xp_cmdshell 'time 12:03:00 ',no_output
waitfor delay '00:00:03 '
go
--12:03:03truncate表中的数据
truncate table dbtest.dbo.t
go

--5
--改时间
exec master..xp_cmdshell 'date 07-27-06 ',no_output--2006-07-27
exec master..xp_cmdshell 'time 12:04:00 ',no_output
waitfor delay '00:00:03 '
go
--12:04:03备份数据库日志
backup log dbtest to disk= 'c:\dbtest_log.bak ' with format
go

--恢复数据库到时间点

--1
--恢复数据文件
restore database dbtest from disk= 'c:\dbtest.bak ' with replace,norecovery
go
--恢复日志到2006-07-27 12:00:10
restore log dbtest from disk= 'c:\dbtest_log.bak ' with recovery,stopat= '2006-07-27 12:00:10 '
go
if exists(select * from dbtest.dbo.sysobjects where xtype= 'U ' and name= 't ')
select 'table t exist '
else
select 'table t not exist '
go

--2
--恢复数据文件
restore database dbtest from disk= 'c:\dbtest.bak ' with replace,norecovery
go
--恢复日志到2006-07-27 12:01:10
restore log dbtest from disk= 'c:\dbtest_log.bak ' with recovery,stopat= '2006-07-27 12:01:10 '
go
select * from dbtest.dbo.t
go

--3
--恢复数据文件
restore database dbtest from disk= 'c:\dbtest.bak ' with replace,norecovery
go
--恢复日志到2006-07-27 12:02:10
restore log dbtest from disk= 'c:\dbtest_log.bak ' with recovery,stopat= '2006-07-27 12:02:10 '
go
select * from dbtest.dbo.t
go

--4