How to alter INFORMATION_SCHEMA or add triggers or foreign keys to it?(如何更改 INFORMATION_SCHEMA 或添加触发器或外键?)
问题描述
我正在尝试创建一些元数据来扩展 mysql 功能,但我无法在数据库 INFORMATION_SCHEMA 中创建表.我认为我可以创建另一个数据库并在其中保存我的元数据,但我需要一些外键从我的表到 INFORMATION_SCHEMA 数据库中的一些表.不过,我在尝试创建它们时会出错.然后我想我可以创建一个触发器来获得更改通知,但是由于触发器与表相关联,我无法更改该数据库,因此我也无法创建触发器.
I'm trying to create some meta-data to extend mysql functionality but I can't create tables in the database INFORMATION_SCHEMA. I thought that I could just create another database and have my metadata in there but I need some foreign keys from my tables to some tables in the INFORMATION_SCHEMA DB. Nevertheless, I get errors when trying to create them. Then I thought I could create a trigger to get notified of changes but since triggers are associated to a table and I can't alter that database, I can't create triggers either.
具体来说,我有一些表引用了 information_schema.schema(schema_name)
和 information_schema.schemata(columns)
和其他一些表.我想要那些外键,这样我就可以使用 ON UPDATE CASCADE ON DELETE CASCADE
否则我的表中会有一些行没有引用,我不能允许这样做.
Specifically I have some tables that references to information_schema.schemata(schema_name)
and to information_schema.schemata(columns)
and some others. I want to have those foreign key so I can use ON UPDATE CASCADE ON DELETE CASCADE
or otherwise I'll have some rows in my tables referencing to nothing and I can't allow that.
我正在使用使用 MySql 5.3 的 mariaDB 5.5.30.
I'm using mariaDB 5.5.30 which uses MySql 5.3.
推荐答案
INFORMATION_SCHEMA 表实际上是视图,其内容由 MySQL 服务器自动维护.
INFORMATION_SCHEMA tables are actually views whose contents is automatically maintained by the MySQL server.
手册提供了更多信息:
在 INFORMATION_SCHEMA 内部有几个只读表.他们实际上是视图,而不是基表,因此没有关联的文件与他们一起,你不能在他们身上设置触发器.另外,没有具有该名称的数据库目录.
Inside INFORMATION_SCHEMA there are several read-only tables. They are actually views, not base tables, so there are no files associated with them, and you cannot set triggers on them. Also, there is no database directory with that name.
虽然您可以选择 INFORMATION_SCHEMA 作为默认数据库使用 USE 语句,只能读取表的内容,不能读取对它们执行 INSERT、UPDATE 或 DELETE 操作.
Although you can select INFORMATION_SCHEMA as the default database with a USE statement, you can only read the contents of tables, not perform INSERT, UPDATE, or DELETE operations on them.
这篇关于如何更改 INFORMATION_SCHEMA 或添加触发器或外键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何更改 INFORMATION_SCHEMA 或添加触发器或外键?


- 导入具有可变标题的 Excel 文件 2021-01-01
- 更改自动增量起始编号? 2021-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- SQL 临时表问题 2022-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01