在 Access 中选择性删除许多表?

发布于 2024-08-21 12:54:43 字数 550 浏览 2 评论 0原文

我需要删除 Access 2003 中 180 个表中的 175 个(使用 Access 2000 格式数据库)。我尝试的第一件事是转到表列表并尝试选择全部,按住 Control 键单击我想要保留的表,然后选择“删除”。然而,事实证明你一次只能选择一个。

然后我找到了一种方法以纯文本形式获取所有表名称的列表,并使用 Vim 制作了一堆 drop 语句:(

drop table table_1;
drop table table_2;
...
drop table table_175;

显然,这些不是真实姓名。)这些语句有效它们本身就很好(即,一次只执行一个,但是当我尝试运行其中两个或多个时,我收到一条错误消息:

Syntax error in DROP TABLE or DROP INDEX.

这似乎违背了目的。哦,Access...你总是让我想要让我抓狂。

为了完成这项工作,我缺少什么?任何能让我保留我需要的表格的过程都很棒(不过,我想避免学习任何 Visual Basic。)

I need to drop 175 of 180 tables in Access 2003 (using an Access 2000 format database). The first thing I tried was going to the table list and trying to select all, control-clicking the ones I want to keep, and choosing "Delete". However, it turns out you can only select one at a time.

Then I found out a way to get a list of all the table names as plain text and made a bunch of drop statements using Vim:

drop table table_1;
drop table table_2;
...
drop table table_175;

(Obviously, those aren't the real names.) These statements work fine by themselves (i.e., just executing one at a time, but when I try to run 2 or more of them, I get an error message:

Syntax error in DROP TABLE or DROP INDEX.

That seems to defeat the purpose. Oh, Access... you always make me want to pull my hair out.

What am I missing to make this work? Any process that will let me keep the few tables I need for my purposes would be great. (I'd like to avoid learning any Visual Basic, though.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

九命猫 2024-08-28 12:54:43

Remou 已经解决了您的问题,但作为建议,您可能需要将要保留的表导入到新文件中。您可以选择多个文件及其数据。除非您还有很多表,否则您最终可能会得到一个更干净的文件。

Remou has the answer to your problem, but as a suggestion, you may want to import the tables you want to keep into a new file. You can select multiple files and their data. You may end up with a cleaner file unless you have a lot of tables that remain.

油焖大侠 2024-08-28 12:54:43

使用VBA。

For Each tbl In CurrentDb.TableDefs
    If Left(tbl.Name,4) <> "Msys" Then
        s = "DROP TABLE " & tbl.Name
        CurrentDb.Execute s
    End If
Next

For i = ( CurrentDb.TableDefs.Count - 1 ) To 0 Step -1
    If Left(tbl.Name,4) <> "Msys" Then
        ''Debug.Print CurrentDb.TableDefs(i).Name
        CurrentDb.TableDefs.Delete CurrentDb.TableDefs(i).Name
    End If
Next

如果您想要删除特定表或表相关,您可能必须提供一个数组或记录集并对其进行迭代。

Use VBA.

For Each tbl In CurrentDb.TableDefs
    If Left(tbl.Name,4) <> "Msys" Then
        s = "DROP TABLE " & tbl.Name
        CurrentDb.Execute s
    End If
Next

For i = ( CurrentDb.TableDefs.Count - 1 ) To 0 Step -1
    If Left(tbl.Name,4) <> "Msys" Then
        ''Debug.Print CurrentDb.TableDefs(i).Name
        CurrentDb.TableDefs.Delete CurrentDb.TableDefs(i).Name
    End If
Next

You may have to provide an array or recordset and iterate through that if you want to delete specific tables or if tables are related.

最近可好 2024-08-28 12:54:43

如上所述,一般来说,我们使用对象模型和 VBA 来删除表定义及其数据。

您无法在 Access 中运行 SQL 批处理,同样,迭代多个 SQL 语句的方法是在 VBA 中。

Access 不是基于控制台的 RDBMS,您无法像在 SQL Plus 中那样运行批处理脚本,如果您尝试这样做,您肯定会抓狂。

Access 是一个应用程序容器和分析工具,所有过程应用程序都使用 VBA 或宏,这明显不如 VBA 灵活。如果您学习一些 VBA,您将能够从 Access 中获得最大收益。如果没有 VBA,访问将受到极大限制,并且您将能够访问的功能是简单的即席查询。

As described above generally speaking we use the object model and VBA to remove table definitions and their data.

You can't run SQL batches in Access, again the way to iterate through multiple SQL statements is in VBA.

Access isn't a console-based RDBMS and you can't run batch scripts like you can in SQL Plus and you'll certainly be pulling your hair out if you try.

Access is an application container and analysis tool and all procedural applications use either VBA or Macros which significantly less flexible than VBA. You'll get the most from Access if you do learn some VBA. Access is extremely limited without VBA and the functionality that you'll be able to access is simple ad-hoc querying.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文