How to alter INFORMATION_SCHEMA or add triggers or foreign keys to it?

孤街醉人 提交于 2020-01-05 08:01:34

问题


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.

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.

I'm using mariaDB 5.5.30 which uses MySql 5.3.


回答1:


INFORMATION_SCHEMA tables are actually views whose contents is automatically maintained by the MySQL server.

The manual gives more information:

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.

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.




回答2:


They are not really views but temporary tables, that's why you don't see folders. show create view views; ERROR 1347 (HY000): 'information_schema./tmp/#sql_2ac_0' is not VIEW



来源:https://stackoverflow.com/questions/16502166/how-to-alter-information-schema-or-add-triggers-or-foreign-keys-to-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!