From: Daevid Vincent Date: July 1 2006 3:53am Subject: RE: Need way to see all relations? List-Archive: http://lists.mysql.com/mysql/199553 Message-Id: <000901c69cc1$eee53de0$450a0a0a@locutus> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable EXCELLENT! Thanks!=20 > -----Original Message----- > From: Peter Brawley [mailto:peter.brawley@stripped]=20 > Sent: Friday, June 30, 2006 8:31 PM > To: Daevid Vincent > Cc: mysql@stripped > Subject: Re: Need way to see all relations? >=20 > Daevid, >=20 > >I have a 'users' table. And there are all kinds of related > >tables like 'logs', 'preferences', etc. that all have a FK=20 > >reference back to this user ID. > >I want to make a query or use some PHP to build a list of=20 > >all tables in my DB that are references. >=20 > Query to find tables with FK references to $db.$table: >=20 > SELECT=20 > c.table_schema,u.table_name,u.column_name,u.referenced_column_name > FROM information_schema.table_constraints AS c > INNER JOIN information_schema.key_column_usage AS u > USING( constraint_schema, constraint_name ) > WHERE c.constraint_type =3D 'FOREIGN KEY' . > AND u.referenced_table_schema=3D'$db' > AND u.referenced_table_name =3D '$table' > ORDER BY c.table_schema,u.table_name; >=20 > PB >=20 > Daevid Vincent wrote: > > Is there a way with InnoDB tables to see all related tables/columns? > > > > Basically what I want to do is make a script that somehow=20 > will dynamically > > create a "backup" of a single user record. But I don't want=20 > to have to > > manually add a new table or column everytime to the script. > > > > So for example, I have a 'users' table. And there are all=20 > kinds of related > > tables like 'logs', 'preferences', etc. that all have a FK=20 > reference back to > > this user ID. > > > > I want to make a query or use some PHP to build a list of=20 > all tables in my > > DB that are references. > > > > Then I can just dump out that user ID (via this script) and=20 > it will backup > > that user and all related table data across all tables. > > > > =D0=C65=CF=D0=20 > > > > > > =20 >=20 >=20 > --=20 > No virus found in this outgoing message. > Checked by AVG Free Edition. > Version: 7.1.394 / Virus Database: 268.9.8/380 - Release=20 > Date: 6/30/2006 >=20 >=20