mysql - SQL foreign key restraint referencing information_schema -
is possible "constrain" columns in 1 table "reference" columns views in information_schema
in way (it needn't proper foreign key constraint, hence scare quotes)?-- need minimally-intrusive way of adding arbitrary metadata existing column data (e.g. add "comments" e.g. value shop.cheeses.name
shop.cheeses.id =
n), , thought of defining table such:
create table shop.metadata ( `table_schema` varchar(64) not null, `table_name` varchar(64) not null, `column_name` varchar(64) not null, `record_id` int(11) unsigned not null, `comments` text not null, /* show purpose of table */ primary key (`table_schema`, `table_name`, `column_name`, `record_id`), foreign key (`table_schema`, `table_name`, `column_name`) references information_schema.tables(`table_schema`, `table_name`, `column_name`) );
however, statement returns error 1215 (hy000): cannot add foreign key constraint
, presumably because table_schema
, table_name
, column_name
not defined unique
(edit: if columns unique, seems wouldn't possible because can't reference views in foreign key constraints).
still, there no other way define requirement
shop.metadata.table_schema
must contain extant valueinformation_schema.tables.table_schema
shop.metadata.table_name
must contain extant valueinformation_schema.tables.table_name
shop.metadata.column_name
must contain extant valueinformation_schema.tables.column_name
- any quadruple of
(table_schema, table_name, column_name, record_id)
unique?
thanks help.
Comments
Post a Comment