如何删除 Firebird 1.5 数据库中的所有触发器

发布于 2024-09-16 15:49:48 字数 201 浏览 8 评论 0原文

出于调试目的,我需要将现有 Firebird 1.5 数据库的 1 个表发送给某人。

我不想发送整个数据库,而是只想发送仅包含此表的数据库 - 没有触发器,没有约束。我无法将数据复制到另一个数据库,因为我们只是想检查 - 为什么这个表出现问题。

我只是想知道是否有一种方法可以删除所有触发器、所有约束和除一个表之外的所有表(对系统表等使用一些巧妙的技巧)?

For debug purposes I need to send 1 table of an existing Firebird 1.5 database to someone.

In stead of sending the whole db , I want to send just the db with just this table - no triggers, no constraints. I can't copy the data to another db because it's just that that we want to check - why this one table is given troubles.

I am just wondering if there is a way to drop all triggers , all constraints and all but one table (using some clever trick with the system tables or so ) ?

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

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

发布评论

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

评论(3

笑咖 2024-09-23 15:49:48

使用 GUI 工具(我个人更喜欢 IBExpert)执行以下命令:

select 'DROP TRIGGER ' || rdb$trigger_name || ';' from rdb$triggers
  where (rdb$system_flag = 0 or rdb$system_flag is null)

将结果复制到剪贴板然后在脚本执行程序中粘贴并执行
窗户。

Using GUI tool (I personally prefer IBExpert) execute following command:

select 'DROP TRIGGER ' || rdb$trigger_name || ';' from rdb$triggers
  where (rdb$system_flag = 0 or rdb$system_flag is null)

Copy result into clipboard then paste and execute within script executive
window.

执妄 2024-09-23 15:49:48

如果您的数据库备份可以切换到 Firebird 2.1,则 gbak 和 isql

一些 Firebird 命令行工具有
配备了新开关
抑制自动射击
数据库触发器:

<前><代码>gbak -nodbtriggers
isql-nodbtriggers
备份-T

这些开关只能由
数据库所有者和 SYSDBA。

If your database backup can switch to Firebird 2.1 there is some switch in gbak and isql.

Some Firebird command-line tools have
been supplied with new switches to
suppress the automatic firing of
database triggers:

gbak -nodbtriggers
isql -nodbtriggers
nbackup -T

These switches can only be used by the
database owner and SYSDBA.

坚持沉默 2024-09-23 15:49:48

您可以通过直接从系统表中删除所有触发器来删除它们,如下所示:

delete from rdb$triggers
    where (rdb$system_flag = 0 or rdb$system_flag is null);

请注意,使用删除触发器的正常方法当然是更好的选择,但它是可以完成的。

您还可以通过执行 DDL 语句来删除约束,但要枚举约束并将其删除到 SQL 脚本中,您需要 Firebird 1.5 所没有的 execute block 功能。

有类似的语句可以删除其他数据库对象,但由于对象之间的依赖关系,实际成功运行这些语句可能要困难得多。只要另一个对象依赖于任何对象,您就无法删除该对象。由于循环引用,这可能变得非常棘手,其中两个(甚至更多)对象相互依赖,形成一个循环,因此没有一个可以首先被删除。

解决这个问题的方法是打破其中一个依赖关系。例如,可以将依赖于其他对象的过程更改为空主体,之后它不再依赖于其他对象,因此可以将其删除。删除外键是消除表之间依赖关系的另一种方法。

我不知道有任何工具可以实现这种部分删除数据库对象的功能,在我看来,您的用例远非常见。不过,您可以查看 FlameRobin 源代码,它具有一定的用于为数据库对象创建 DDL 脚本或修改语句的代码中的依赖性检测量。有了这些信息,您就可以编写自己的工具来做到这一点。

不过,如果这是一次性的事情,手动完成可能就足够了。为此,请使用您选择的任何 Firebird 管理工具。

You can drop all triggers by directly deleting them from the system table, like so:

delete from rdb$triggers
    where (rdb$system_flag = 0 or rdb$system_flag is null);

Note that the normal way of using drop trigger is certainly preferable, but it can be done.

You can also drop constraints by executing DDL statements, but to enumerate constraints and drop them in a SQL script you would need the execute block functionality that Firebird 1.5 doesn't have.

There are similar statements to delete other database objects, but actually running these successfully may be much more difficult because of dependencies between objects. You can't drop any object as long as another object depends on it. This can become really tricky due to circular references, where two (or even more) objects depend on one another, forming a cycle, so there isn't a single one that may be dropped first.

The way around this is to break one of the dependencies. A procedure for example that has dependencies to other objects can be altered to have an empty body, after which it does no longer depend on those other objects, so they may be dropped then. Dropping foreign keys is another way of eliminating dependencies between tables.

I don't know of any tool implementing such a partial delete of database objects, your use case is IMO far from common. You could however have a look at the FlameRobin source code which has a certain amount of dependency detection in the code that is used to create DDL scripts or modification statements for database objects. Armed with that information you could write your own tool to do it.

If it's a one time thing it may be enough to do this manually, though. Use any Firebird management tool of your choice for that.

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