just_a_newbie
just_a_newbie

Reputation: 375

What is the MySQL command to check if a field of table A is already referenced to a field of table B as the foreign key?

As the question says, what is the MySQL command to check if a field of table A is already referenced to a field of table B as the foreign key? Are there any commands to let the user know it?

Upvotes: 1

Views: 44

Answers (2)

ApplePie
ApplePie

Reputation: 8942

You can use the systems table for this purpose, however from your previous question I think this might be the wrong way to achieve whatever you are trying to achieve.

http://dev.mysql.com/doc/refman/5.6/en/innodb-sys-foreign-table.html

Upvotes: 0

Rahul Tripathi
Rahul Tripathi

Reputation: 172458

Are you looking for something like this:-

USE information_schema;
SELECT *
FROM
  KEY_COLUMN_USAGE
WHERE
  REFERENCED_TABLE_NAME = 'A'
  AND REFERENCED_COLUMN_NAME = 'A_id';

Upvotes: 1

Related Questions