List:General Discussion« Previous MessageNext Message »
From:Baron Schwartz Date:July 3 2010 8:26pm
Subject:Re: Retrieving table and field a foreign key references
View as plain text  
Kris,

You can use SHOW CREATE TABLE.

On Fri, Jul 2, 2010 at 7:56 PM, Kris <mkgnu@stripped> wrote:
> Hello,
>
> I am having trouble finding a way to retrieve the table and field a
> foreign key references by querying MySQL. If you look at the following
> example tables, there is no way after the tables are created to learn
> that:
>  - address.sid actually references state.id
>
>
> Is this possible ?
>
>
>
> For example, the following do not provide this information:
>
> - show create table address;
> - describe address;
> - select * from TABLE_CONSTRAINTS;
> - select * from key_column_usage;
>
> CREATE TABLE state
> (
> id VARCHAR(2) PRIMARY KEY,
> name TEXT
> );
>
> CREATE TABLE address
> (id INT PRIMARY KEY,
> address text,
> zipcode INT,
> sid VARCHAR(2),
> FOREIGN KEY(sid) REFERENCES state(id)
> );
>
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:    http://lists.mysql.com/mysql?unsub=1
>
>



-- 
Baron Schwartz
Percona Inc <http://www.percona.com/>
Consulting, Training, Support & Services for MySQL
Thread
Retrieving table and field a foreign key referencesKris3 Jul
  • Re: Retrieving table and field a foreign key referencesPeter Brawley3 Jul
  • Re: Retrieving table and field a foreign key referencesBaron Schwartz3 Jul