英文(删除access数据库中的所有数据)-钱玉炜
Access软件网QQ交流学习群(群号码198465573),欢迎您的加入!
首页 >技术文章> Access数据库-表


英文(删除access数据库中的所有数据)

发表时间:2008/6/25 14:58:29 评论(0) 浏览(4838)  评论 | 加入收藏 | 复制
   
摘 要:英文(删除Access数据库中的所有数据)
正 文:

Deleting all data from an Access database

Sometimes it may be necessary to delete all the data in a database
while retaining the table structure. If done manually, this job can
quickly become tedious. If your database has many tables, the
following code will clear all the data in a hurry.

Dim ctr As Container, doc As Document, db As Database
Set db = CurrentDB()
Set ctr = db.Containers!Tables
For Each doc in ctr.Documents
   If Left$(doc.Name, 4) <> "MSys" Then 注释:Table is not a system table
        db.Execute "Delete [" & doc.Name & "].*" & _
           "From [" & doc.Name & "];"
   End If
Next doc

You might not want to delete data from linked tables. This can be easily
accommodated by checking the Connect property for each TableDef document.
The modified code reads:

Dim ctr As Container, doc As Document, db As Database
Set db = CurrentDb()
Set ctr = db.Containers!tables
For Each doc In ctr.Documents
   If Left$(doc.Name, 4) <> "MSys" And _
     db.TableDefs(doc.Name).Connect = "" Then
   注释:Table is not a system table or a linked table
     db.Execute "Delete [" & doc.Name & "].*" & _
       "From [" & doc.Name & "];"
   End If
Next doc

You must also have cascading updates/deletes enabled for this procedure
to clear the data from all tables. As an alternative, run the code
multiple times. On the first pass through the database, the tables on
one side of the relationship are cleared, allowing the remaining tables
to be cleared on the next pass.

This tip was contributed by Dr. Michael S. Stoner, Henri Kover, and Stephen Bond


Access软件网交流QQ群(群号:198465573)
 
 相关文章
删除access数据库中的所有数据  【umvsoft整理  2008/7/19】
常见问答
技术分类
相关资源
文章搜索
关于作者

钱玉炜

文章分类

文章存档

友情链接