views:

283

answers:

5

I want to drop a table but it is referenced by one or more other tables. How can I find out which tables are referencing this table without having to look at each of the tables in the database one by one?

A: 

Use Toad to load it up and you can view the references through the diagram. also make sure that you don't have any app code passing sql from the front-end, dropping the table may cause the app to break.

Download link http://www.toadsoft.com/toadmysql/FreewareDownload.htm

If you are using innoDB try this one SHOW TABLE STATUS FROM yourdatabasename LIKE 'T' http://dev.mysql.com/doc/refman/5.1/en/show-table-status.html

CodeToGlory
I'm using Linux so the tool you suggest will not work.
If you are using innoDB try this oneSHOW TABLE STATUS FROM yourdatabasename LIKE 'T' http://dev.mysql.com/doc/refman/5.1/en/show-table-status.html
CodeToGlory
+1  A: 
select table_name 
from information_schema.referential_constraints 
where referenced_table_name = 'parent table here';
Michael Buen
The table referential_constraints does not exist in information_schema. I was looking in this database for an answer but can't find it.MySQL version is 5.0.51a-24-log (Debian)
i'm using 5.1.31
Michael Buen
A: 
select table_name
from KEY_COLUMN_USAGE
where table_schema = 'my_database'
and referenced_table_name = 'my_table_here';

This works.

A: 

Look at the KEY_COLUMN_USAGE table in the iformation_schema schema.

Milhous
A: 

from the mysql command line: show table status

Will Glass