mysql - Display all tables that have a foreign key equal to a value -
i'm going attempt describe in best way can. need test deletion processing through tables in database. tables need checked ones have foreign key users
table primary key userid
. want pull in tables have foreign key equal specific value.
the following query pulls in tables have foreign key userid
use information_schema; select table_name key_column_usage referenced_table_name = 'users' , referenced_column_name = 'userid' , table_schema = 'erik_rm12_working41_main';
i need way check tables listed have value in foreign key equal specific value, 26.
i not able understand requirement clearly... based on understanding given query... can try , let know, if required.
select f.name foreignkey, object_name(f.parent_object_id) tablename, col_name(fc.parent_object_id, fc.parent_column_id) columnname, object_name (f.referenced_object_id) referencetablename, col_name(fc.referenced_object_id, fc.referenced_column_id) referencecolumnname sys.foreign_keys f inner join sys.foreign_key_columns fc on f.object_id = fc.constraint_object_id object_name(f.parent_object_id)= '**<table_name>**'
Comments
Post a Comment