删除Access数据库中的所有数据

最美时代的人生

最美时代的人生

2016-02-19 17:53

今天图老师小编给大家展示的是删除Access数据库中的所有数据,精心挑选的内容希望大家多多支持、多多分享,喜欢就赶紧get哦!

  Deleting all data from an Access database

(本文来源于图老师网站,更多请访问https://m.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.查看 。

(本文来源于图老师网站,更多请访问https://m.tulaoshi.com/bianchengyuyan/)
展开更多 50%)
分享

猜你喜欢

删除Access数据库中的所有数据

编程语言 网络编程
删除Access数据库中的所有数据

删除Access数据库中的空记录

编程语言 网络编程
删除Access数据库中的空记录

s8lol主宰符文怎么配

英雄联盟 网络游戏
s8lol主宰符文怎么配

Word中插入Access、SQL数据库数据

办公软件
Word中插入Access、SQL数据库数据

sql 语句 取数据库服务器上所有数据库的名字

编程语言 网络编程
sql 语句 取数据库服务器上所有数据库的名字

lol偷钱流符文搭配推荐

英雄联盟 网络游戏
lol偷钱流符文搭配推荐

DELPHI中操作ACCESS数据库

编程语言 网络编程
DELPHI中操作ACCESS数据库

用VB实现关闭所有数据库对象

编程语言 网络编程
用VB实现关闭所有数据库对象

lolAD刺客新符文搭配推荐

英雄联盟
lolAD刺客新符文搭配推荐

ACCESS转化成SQL2000需要注意的问题

ACCESS转化成SQL2000需要注意的问题

Win10对比Win7哪个好

Win10对比Win7哪个好
下拉加载更多内容 ↓