问题:
如何恢复已经删除的记录;如何恢复已经删除的表、窗体等等对象
1、我用 DELETE FROM TABLE 删除了一些记录,现在发现误删除了,该如何恢复?
2、我直接手动删除或者用 DROP TABLE 删除了一个表,现在发现是误删除了,该如何恢复?
3、我手动删除了一个窗体,该如何恢复?
4、我删除了记录,可是数据库体积并没有减小,那么是否能找回记录呢?
回答:
1、已经删除的记录是无法恢复的,ACCESS 不是 FOXPRO,MDB 格式不是 DBF 格式,没有逻辑删除和物理删除的概念,一旦删除就无法恢复了。
2、无法恢复,但是你可以查看一下,有没有隐藏的以 "~" 符号开头的表,更改该表的名称有可能找回你需要的表。
3、无法恢复,但是你可以查看一下有没有系统隐藏的对象,有时候对象被删除时系统并不直接删除,而是更改对象名后隐藏它。
4、数据库体积的确没有变小,你压缩修复数据库后体积就会变小了。那是因为在二进制上你的数据的确没有被删除,仍然存放在磁盘的某个扇区,但是微软没有提供 MDB 格式二进制组织方式的参考资料(微软也不会提供,其他第三方公司也没有权利直接反编译 MDB 格式)。至今为止,中国大陆我也没有看到过相关的参考资料。所以目前为止,你已经删除的数据是无法恢复的。但是你可以尝试使用磁盘恢复软件来找到恢复数据的方法,但是该方法不在本文讨论范围。
建议:在建立数据库结构时,可以在各个表中再多加一个 ISDEL 字段,删除记录时不使用 DELETE FROM ,而使用 UPDATE TABLE SET ISDEL=TRUE 这样的语句,然后在界面上不显示 ISDEL=TRUE 的记录即可。
复制代码 代码如下:
如果还没有被压缩理论上可以。试试这段代码吧。加在access模组中
恢復刪除的工作表(未被壓縮)
Public Function FnUndeleteObjects() As Boolean
On Error GoTo ErrorHandler:
Dim strObjectName As String
Dim rsTables As DAO.Recordset
Dim dbsDatabase As DAO.Database
Dim tDef As DAO.TableDef
Dim qDef As DAO.QueryDef
Dim intNumDeletedItemsFound As Integer
Set dbsDatabase = CurrentDb
For Each tDef In dbsDatabase.TableDefs
'This is actually used as a 'Deleted Flag'
If tDef.Attributes And dbHiddenObject Then
strObjectName = FnGetDeletedTableNameByProp(tDef.Name)
strObjectName = InputBox("A deleted TABLE has been found." & _
vbCrLf & vbCrLf & _
"To undelete this object, enter a new name:", _
"Access Undelete Table", strObjectName)
If Len(strObjectName) > 0 Then
FnUndeleteTable CurrentDb, tDef.Name, strObjectName
End If
intNumDeletedItemsFound = intNumDeletedItemsFound + 1
End If
Next tDef
For Each qDef In dbsDatabase.QueryDefs
'Note 'Attributes' flag is not exposed for QueryDef objects,
'We could look up the flag by using MSysObjects but
'new queries don't get written to MSysObjects until
'Access is closed. Therefore we'll just check the
'start of the name is '~TMPCLP' ...
If InStr(1, qDef.Name, "~TMPCLP") = 1 Then
strObjectName = ""
strObjectName = InputBox("A deleted QUERY has been found." & _
vbCrLf & vbCrLf & _
"To undelete this object, enter a new name:", _
"Access Undelete Query", strObjectName)
If Len(strObjectName) > 0 Then
If FnUndeleteQuery(CurrentDb, qDef.Name, strObjectName) Then
'We'll rename the deleted object since we've made a
'copy and won't be needing to re-undelete it.
'(To break the condition "~TMPCLP" in future...)
qDef.Name = "~TMPCLQ" & Right$(qDef.Name, Len(qDef.Name) - 7)
End If
End If
intNumDeletedItemsFound = intNumDeletedItemsFound + 1
End If
Next qDef
If intNumDeletedItemsFound = 0 Then
MsgBox "Unable to find any deleted tables/queries to undelete!"
End If
Set dbsDatabase = Nothing
FnUndeleteObjects = True
ExitFunction:
Exit Function
ErrorHandler:
MsgBox "Error occured in FnUndeleteObjects() - " & _
Err.Description & " (" & CStr(Err.Number) & ")"
GoTo ExitFunction
End Function
Private Function FnUndeleteTable(dbDatabase As DAO.Database, _
strDeletedTableName As String, _
strNewTableName As String)
'Module (c) 2005 Wayne Phillips (http://www.everythingaccess.com)
'Written 18/04/2005
Dim tDef As DAO.TableDef
Set tDef = dbDatabase.TableDefs(strDeletedTableName)
'Remove the Deleted Flag...
tDef.Attributes = tDef.Attributes And Not dbHiddenObject
'Rename the deleted object to the original or new name...
tDef.Name = strNewTableName
dbDatabase.TableDefs.Refresh
Application.RefreshDatabaseWindow
Set tDef = Nothing
End Function
Private Function FnUndeleteQuery(dbDatabase As DAO.Database, _
strDeletedQueryName As String, _
strNewQueryName As String)
'Module (c) 2005 Wayne Phillips (http://www.everythingaccess.com)
'Written 18/04/2005
'We can't just remove the Deleted flag on queries
'('Attributes' is not an exposed property)
'So instead we create a new query with the SQL...
'Note: Can't use DoCmd.CopyObject as it copies the dbHiddenObject attribute!
If FnCopyQuery(dbDatabase, strDeletedQueryName, strNewQueryName) Then
FnUndeleteQuery = True
Application.RefreshDatabaseWindow
End If
End Function
Private Function FnCopyQuery(dbDatabase As DAO.Database, _
strSourceName As String, _
strDestinationName As String)
'Module (c) 2005 Wayne Phillips (http://www.everythingaccess.com)
'Written 18/04/2005
On Error GoTo ErrorHandler:
Dim qDefOld As DAO.QueryDef
Dim qDefNew As DAO.QueryDef
Dim Field As DAO.Field
Set qDefOld = dbDatabase.QueryDefs(strSourceName)
Set qDefNew = dbDatabase.CreateQueryDef(strDestinationName, qDefOld.SQL)
'Copy root query properties...
FnCopyLvProperties qDefNew, qDefOld.Properties, qDefNew.Properties
For Each Field In qDefOld.Fields
'Copy each fields individual properties...
FnCopyLvProperties qDefNew.Fields(Field.Name), _
Field.Properties, _
qDefNew.Fields(Field.Name).Properties
Next Field
dbDatabase.QueryDefs.Refresh
FnCopyQuery = True
ExitFunction:
Set qDefNew = Nothing
Set qDefOld = Nothing
Exit Function
ErrorHandler:
MsgBox "Error re-creating query '" & strDestinationName & "':" & vbCrLf & _
Err.Description & " (" & CStr(Err.Number) & ")"
GoTo ExitFunction
End Function
Private Function PropExists(Props As DAO.Properties, strPropName As String) As Boolean
'Module (c) 2005 Wayne Phillips (http://www.everythingaccess.com)
'Written 18/04/2005
'If properties fail to be created, we'll just ignore the errors
On Error Resume Next
Dim Prop As DAO.Property
For Each Prop In Props
If Prop.Name = strPropName Then
PropExists = True
Exit Function ' Short circuit
End If
Next Prop
PropExists = False
End Function
Private Sub FnCopyLvProperties(objObject As Object, OldProps As DAO.Properties, NewProps As DAO.Properties)
'Module (c) 2005 Wayne Phillips (http://www.everythingaccess.com)
'Written 18/04/2005
'If properties fail to be created, we'll just ignore the errors
On Error Resume Next
Dim Prop As DAO.Property
Dim NewProp As DAO.Property
For Each Prop In OldProps
If Not PropExists(NewProps, Prop.Name) Then
If IsNumeric(Prop.Value) Then
NewProps.Append objObject.CreateProperty(Prop.Name, Prop.Type, CLng(Prop.Value))
Else
NewProps.Append objObject.CreateProperty(Prop.Name, Prop.Type, Prop.Value)
End If
Else
With NewProps(Prop.Name)
.Type = Prop.Type
.Value = Prop.Value
End With
End If
Next Prop
End Sub
Private Function FnGetDeletedTableNameByProp(strRealTableName As String) As String
'Module (c) 2005 Wayne Phillips (http://www.everythingaccess.com)
'Written 18/04/2005
'If an error occurs here, just ignore (user will override the blank name)
On Error Resume Next
Dim i As Long
Dim strNameMap As String
'Look up the Unicode translation NameMap property to try to guess the
'original table name... (Access 2000+ only - and doesn't always exist?!)
strNameMap = CurrentDb.TableDefs(strRealTableName).Properties("NameMap")
strNameMap = Mid(strNameMap, 23) 'Offset of the table name...
'Find the null terminator...
i = 1
If Len(strNameMap) > 0 Then
While (i < Len(strNameMap)) And (Asc(Mid(strNameMap, i)) <> 0)
i = i + 1
Wend
End If
FnGetDeletedTableNameByProp = Left(strNameMap, i - 1)
End Function
如何恢复已经删除的记录;如何恢复已经删除的表、窗体等等对象
1、我用 DELETE FROM TABLE 删除了一些记录,现在发现误删除了,该如何恢复?
2、我直接手动删除或者用 DROP TABLE 删除了一个表,现在发现是误删除了,该如何恢复?
3、我手动删除了一个窗体,该如何恢复?
4、我删除了记录,可是数据库体积并没有减小,那么是否能找回记录呢?
回答:
1、已经删除的记录是无法恢复的,ACCESS 不是 FOXPRO,MDB 格式不是 DBF 格式,没有逻辑删除和物理删除的概念,一旦删除就无法恢复了。
2、无法恢复,但是你可以查看一下,有没有隐藏的以 "~" 符号开头的表,更改该表的名称有可能找回你需要的表。
3、无法恢复,但是你可以查看一下有没有系统隐藏的对象,有时候对象被删除时系统并不直接删除,而是更改对象名后隐藏它。
4、数据库体积的确没有变小,你压缩修复数据库后体积就会变小了。那是因为在二进制上你的数据的确没有被删除,仍然存放在磁盘的某个扇区,但是微软没有提供 MDB 格式二进制组织方式的参考资料(微软也不会提供,其他第三方公司也没有权利直接反编译 MDB 格式)。至今为止,中国大陆我也没有看到过相关的参考资料。所以目前为止,你已经删除的数据是无法恢复的。但是你可以尝试使用磁盘恢复软件来找到恢复数据的方法,但是该方法不在本文讨论范围。
建议:在建立数据库结构时,可以在各个表中再多加一个 ISDEL 字段,删除记录时不使用 DELETE FROM ,而使用 UPDATE TABLE SET ISDEL=TRUE 这样的语句,然后在界面上不显示 ISDEL=TRUE 的记录即可。
复制代码 代码如下:
如果还没有被压缩理论上可以。试试这段代码吧。加在access模组中
恢復刪除的工作表(未被壓縮)
Public Function FnUndeleteObjects() As Boolean
On Error GoTo ErrorHandler:
Dim strObjectName As String
Dim rsTables As DAO.Recordset
Dim dbsDatabase As DAO.Database
Dim tDef As DAO.TableDef
Dim qDef As DAO.QueryDef
Dim intNumDeletedItemsFound As Integer
Set dbsDatabase = CurrentDb
For Each tDef In dbsDatabase.TableDefs
'This is actually used as a 'Deleted Flag'
If tDef.Attributes And dbHiddenObject Then
strObjectName = FnGetDeletedTableNameByProp(tDef.Name)
strObjectName = InputBox("A deleted TABLE has been found." & _
vbCrLf & vbCrLf & _
"To undelete this object, enter a new name:", _
"Access Undelete Table", strObjectName)
If Len(strObjectName) > 0 Then
FnUndeleteTable CurrentDb, tDef.Name, strObjectName
End If
intNumDeletedItemsFound = intNumDeletedItemsFound + 1
End If
Next tDef
For Each qDef In dbsDatabase.QueryDefs
'Note 'Attributes' flag is not exposed for QueryDef objects,
'We could look up the flag by using MSysObjects but
'new queries don't get written to MSysObjects until
'Access is closed. Therefore we'll just check the
'start of the name is '~TMPCLP' ...
If InStr(1, qDef.Name, "~TMPCLP") = 1 Then
strObjectName = ""
strObjectName = InputBox("A deleted QUERY has been found." & _
vbCrLf & vbCrLf & _
"To undelete this object, enter a new name:", _
"Access Undelete Query", strObjectName)
If Len(strObjectName) > 0 Then
If FnUndeleteQuery(CurrentDb, qDef.Name, strObjectName) Then
'We'll rename the deleted object since we've made a
'copy and won't be needing to re-undelete it.
'(To break the condition "~TMPCLP" in future...)
qDef.Name = "~TMPCLQ" & Right$(qDef.Name, Len(qDef.Name) - 7)
End If
End If
intNumDeletedItemsFound = intNumDeletedItemsFound + 1
End If
Next qDef
If intNumDeletedItemsFound = 0 Then
MsgBox "Unable to find any deleted tables/queries to undelete!"
End If
Set dbsDatabase = Nothing
FnUndeleteObjects = True
ExitFunction:
Exit Function
ErrorHandler:
MsgBox "Error occured in FnUndeleteObjects() - " & _
Err.Description & " (" & CStr(Err.Number) & ")"
GoTo ExitFunction
End Function
Private Function FnUndeleteTable(dbDatabase As DAO.Database, _
strDeletedTableName As String, _
strNewTableName As String)
'Module (c) 2005 Wayne Phillips (http://www.everythingaccess.com)
'Written 18/04/2005
Dim tDef As DAO.TableDef
Set tDef = dbDatabase.TableDefs(strDeletedTableName)
'Remove the Deleted Flag...
tDef.Attributes = tDef.Attributes And Not dbHiddenObject
'Rename the deleted object to the original or new name...
tDef.Name = strNewTableName
dbDatabase.TableDefs.Refresh
Application.RefreshDatabaseWindow
Set tDef = Nothing
End Function
Private Function FnUndeleteQuery(dbDatabase As DAO.Database, _
strDeletedQueryName As String, _
strNewQueryName As String)
'Module (c) 2005 Wayne Phillips (http://www.everythingaccess.com)
'Written 18/04/2005
'We can't just remove the Deleted flag on queries
'('Attributes' is not an exposed property)
'So instead we create a new query with the SQL...
'Note: Can't use DoCmd.CopyObject as it copies the dbHiddenObject attribute!
If FnCopyQuery(dbDatabase, strDeletedQueryName, strNewQueryName) Then
FnUndeleteQuery = True
Application.RefreshDatabaseWindow
End If
End Function
Private Function FnCopyQuery(dbDatabase As DAO.Database, _
strSourceName As String, _
strDestinationName As String)
'Module (c) 2005 Wayne Phillips (http://www.everythingaccess.com)
'Written 18/04/2005
On Error GoTo ErrorHandler:
Dim qDefOld As DAO.QueryDef
Dim qDefNew As DAO.QueryDef
Dim Field As DAO.Field
Set qDefOld = dbDatabase.QueryDefs(strSourceName)
Set qDefNew = dbDatabase.CreateQueryDef(strDestinationName, qDefOld.SQL)
'Copy root query properties...
FnCopyLvProperties qDefNew, qDefOld.Properties, qDefNew.Properties
For Each Field In qDefOld.Fields
'Copy each fields individual properties...
FnCopyLvProperties qDefNew.Fields(Field.Name), _
Field.Properties, _
qDefNew.Fields(Field.Name).Properties
Next Field
dbDatabase.QueryDefs.Refresh
FnCopyQuery = True
ExitFunction:
Set qDefNew = Nothing
Set qDefOld = Nothing
Exit Function
ErrorHandler:
MsgBox "Error re-creating query '" & strDestinationName & "':" & vbCrLf & _
Err.Description & " (" & CStr(Err.Number) & ")"
GoTo ExitFunction
End Function
Private Function PropExists(Props As DAO.Properties, strPropName As String) As Boolean
'Module (c) 2005 Wayne Phillips (http://www.everythingaccess.com)
'Written 18/04/2005
'If properties fail to be created, we'll just ignore the errors
On Error Resume Next
Dim Prop As DAO.Property
For Each Prop In Props
If Prop.Name = strPropName Then
PropExists = True
Exit Function ' Short circuit
End If
Next Prop
PropExists = False
End Function
Private Sub FnCopyLvProperties(objObject As Object, OldProps As DAO.Properties, NewProps As DAO.Properties)
'Module (c) 2005 Wayne Phillips (http://www.everythingaccess.com)
'Written 18/04/2005
'If properties fail to be created, we'll just ignore the errors
On Error Resume Next
Dim Prop As DAO.Property
Dim NewProp As DAO.Property
For Each Prop In OldProps
If Not PropExists(NewProps, Prop.Name) Then
If IsNumeric(Prop.Value) Then
NewProps.Append objObject.CreateProperty(Prop.Name, Prop.Type, CLng(Prop.Value))
Else
NewProps.Append objObject.CreateProperty(Prop.Name, Prop.Type, Prop.Value)
End If
Else
With NewProps(Prop.Name)
.Type = Prop.Type
.Value = Prop.Value
End With
End If
Next Prop
End Sub
Private Function FnGetDeletedTableNameByProp(strRealTableName As String) As String
'Module (c) 2005 Wayne Phillips (http://www.everythingaccess.com)
'Written 18/04/2005
'If an error occurs here, just ignore (user will override the blank name)
On Error Resume Next
Dim i As Long
Dim strNameMap As String
'Look up the Unicode translation NameMap property to try to guess the
'original table name... (Access 2000+ only - and doesn't always exist?!)
strNameMap = CurrentDb.TableDefs(strRealTableName).Properties("NameMap")
strNameMap = Mid(strNameMap, 23) 'Offset of the table name...
'Find the null terminator...
i = 1
If Len(strNameMap) > 0 Then
While (i < Len(strNameMap)) And (Asc(Mid(strNameMap, i)) <> 0)
i = i + 1
Wend
End If
FnGetDeletedTableNameByProp = Left(strNameMap, i - 1)
End Function
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
白云城资源网 Copyright www.dyhadc.com
暂无“access下如何恢复已经删除的记录;如何恢复已经删除的表、窗体等等对象”评论...
稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!
昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。
这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。
而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?
更新日志
2024年11月05日
2024年11月05日
- 雨林唱片《赏》新曲+精选集SACD版[ISO][2.3G]
- 罗大佑与OK男女合唱团.1995-再会吧!素兰【音乐工厂】【WAV+CUE】
- 草蜢.1993-宝贝对不起(国)【宝丽金】【WAV+CUE】
- 杨培安.2009-抒·情(EP)【擎天娱乐】【WAV+CUE】
- 周慧敏《EndlessDream》[WAV+CUE]
- 彭芳《纯色角3》2007[WAV+CUE]
- 江志丰2008-今生为你[豪记][WAV+CUE]
- 罗大佑1994《恋曲2000》音乐工厂[WAV+CUE][1G]
- 群星《一首歌一个故事》赵英俊某些作品重唱企划[FLAC分轨][1G]
- 群星《网易云英文歌曲播放量TOP100》[MP3][1G]
- 方大同.2024-梦想家TheDreamer【赋音乐】【FLAC分轨】
- 李慧珍.2007-爱死了【华谊兄弟】【WAV+CUE】
- 王大文.2019-国际太空站【环球】【FLAC分轨】
- 群星《2022超好听的十倍音质网络歌曲(163)》U盘音乐[WAV分轨][1.1G]
- 童丽《啼笑姻缘》头版限量编号24K金碟[低速原抓WAV+CUE][1.1G]