今天图老师小编给大家展示的是删除Access数据库中的所有数据,精心挑选的内容希望大家多多支持、多多分享,喜欢就赶紧get哦!
【 tulaoshi.com - 编程语言 】
Deleting all data from an Access database
(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/bianchengyuyan/)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.查看 。
来源:http://www.tulaoshi.com/n/20160219/1616278.html
看过《删除Access数据库中的所有数据》的人还看了以下文章 更多>>