MySql Finding a tree structure using Reference Keys -


we have parent table stores user details. since doing soft delete. due legal commitments, forced hard delete user details.

so problem main table referenced many places. able find referenced tables following query in mysql

use information_schema; select table_name, column_name,constraint_name   key_column_usage   referenced_table_name = 'projectuser'   , referenced_column_name = 'userid'   , table_schema = 'testproduct'; 

it success got tables around 45. real problem is, possible child table of "projectuser" may referenced somewhere else.

for example, 1 of child table useraddress used foriegn key other table. how can query bring tables, reference projectuser, , child tables , grand child tables?

there no query that's going out of mess. can write program successively run queries build structure, not able in 1 query.

1) use mysqldump, write parse dump , build tree

2) use tool visualize schema such (schemaspy)[http://schemaspy.sourceforge.net/] or (mysql workbench)[http://www.mysql.com/products/workbench/]

3) take @almado's suggestion , add on delete cascade. can drop existing foreign key , readd using later table function. if have problems re adding foreign key due constraint violation, disable keys while re add foreign key.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -