Access开发培训
网站公告
·Access专家课堂QQ群号:151711184    ·Access快速开发平台下载地址及教程    ·欢迎加入Access专家课堂微信群!    ·如何快速搜索本站文章|示例|资料    
您的位置: 首页 > 技术文章 > Access数据库-表

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

时 间:2008-06-25 14:58:29
作 者:umvsoft整理   ID:16  城市:江阴
摘 要:英文(删除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交流群 (群号:483923997)       Access源码网店

常见问答:

技术分类:

相关资源:

专栏作家

关于我们 | 服务条款 | 在线投稿 | 友情链接 | 网站统计 | 网站帮助