是否可以在 information_schema 中的任何表上应用触发器?

发布于 2024-08-26 12:37:25 字数 44 浏览 5 评论 0原文

是否可以在 information_schema 中的任何表上应用触发器?

Is it possible to apply trigger on any table in information_schema?

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

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

发布评论

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

评论(2

私藏温柔 2024-09-02 12:37:25

据我了解,information_schema 中的表实际上是视图。 此处提到了这一点。

根据 MySQL 的规定,您不能在临时表或视图上创建触发器。有关相关讨论,请参阅此页面

所以,根据这些信息我会说不。我确信如果我在这一点上错了,有人会纠正我。

有一个类似于您所要求的讨论此处

你想实现什么目标?

It is my understanding that the tables in information_schema are really views. This is mentioned here.

According to MySQL, you can't make triggers on temp tables or views. See this page for a discussion about that.

So, I'm going to say no based on that information. I'm sure someone will correct me if I'm wrong on this.

There is a discussion similar to what you are asking here.

What are you trying to accomplish?

高速公鹿 2024-09-02 12:37:25

那里有更聪明的人——
开玩笑,但不幸的是,我一直在尝试做同样的事情,唯一明显的答案是添加一个抽象层。

简而言之,您需要用另一种语言调用更高级别的函数(由您自己编写),而不只是 SQL("ALTER TABLE ...."),如下所示:

->

modifytable( $old_table_structure,$new_table_structure){
 alter_table_base_table($old_table_structure,$new_table_structure);
 alter_table_history_table($old_table_structure,$new_table_structure); //just guessing   that's what I'm doing with it so thought it was the same for you
 alter_history_triggers($old_table_structure,$new_table_structure);
}

我真的很想直接在 DBMS 中执行此操作,但似乎 information_schema 并不是为此目的。

当然,您会希望在一笔交易中拥有所有这些,以确保它不会爆炸;)

Someone smarter is there --
Just kidding but I've been trying to do the same thing and the only obvious answer is to add an abstraction layer, unfortunately.

Simply put, instead of just SQL("ALTER TABLE ....") you will need to call a higher level function (written by yourself) in another language, like this:

->

modifytable( $old_table_structure,$new_table_structure){
 alter_table_base_table($old_table_structure,$new_table_structure);
 alter_table_history_table($old_table_structure,$new_table_structure); //just guessing   that's what I'm doing with it so thought it was the same for you
 alter_history_triggers($old_table_structure,$new_table_structure);
}

I really wanted to do this straight in the DBMS, but it seems like information_schema wasn't meant for that.

And of course, you'll want to have all that in one transaction, to make sure it doesn't explode ;)

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