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

2016-02-19 17:53 0 1 收藏

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

【 tulaoshi.com - 编程语言 】

  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

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/bianchengyuyan/)

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

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/bianchengyuyan/)

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://www.tulaoshi.com/n/20160219/1616278.html

延伸阅读
问:我怎样才能将Microsoft Access数据表中的数据转换为XML格式? 答:以下应用程序可以帮助您将Access数据转换为XML格式:Access 2002、 ADO 2.5和SQLXML。您可以通过Access 2002(Microsoft Office XP的一部分)查询数据或者使用XML格式保存数据。您可能想自动完成这个转换过程。ADO 2.5及其后续版本使您可以将数据打开到一个记录...
标签: vb
  如果您在Access数据库、Access项目中删除数据或对象,可能会产生碎片并导致磁盘空间使用效率的降低。同时,数据库文件的大小并未减小,而是不断的增大,直至您的硬盘没有空间。有没有好的处理方法呢?其实,在Access中可以对数据库进行压缩优化以提升Access数据库和Access项目的性能,这样的压缩处理的实质是复制该文件,并重新组织文件...
适用:ACCESS2000 ACCESS97 数据库规格是MDB的工作极限,以下列出ACCESS2000的规格,与ACCESS97只有极少差异,有差异者皆特别注明。 ●数据库 数据库档案大小 : 20亿字节(ACCESS97为10亿字节) 一个数据库内的组件数目: 32,768 模快 : 1024 一个组件名称的字节数 : 64 一个密码的字节数 : 14 ...
面向:初学者。 目的:如果一年的数据较多,希望在分年的数据库中保存数据。 知识点: 1.数据库拆分。 2.文件查找技术。 3.文件复制。 4.链接表的刷新。 步骤: 1.将一些每年都要使用(修改,添加等)的表的名称前两个字母改为共同的(如:Or_业务人员名单,Or_收货人名单等),注意不要是“MS”,“SW”,“US”等系统要使用的字母。 2.将...
标签: excel
Excel中的数据如何导入到Access数据库中?   现在大多数人记录数据都是用excel,但是一些程序员需要将Excel中的数据导入Access数据库中,编写一个另外的程序,但是对于初学者来说这还是挺艰难的,那么现在我就为大家讲解如何将Excel中的数据导入到Access数据库中。 找到自己需要做改变的Excel和Access 为了避免自己以后...

经验教程

984

收藏

82
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部