MySQL queries the foreign key of a table

Source: Internet
Author: User
Tags mysql query

MySQL and Oracle also have a data dictionary table, there is a separate library called Information_schema, to see the foreign key of a table to look up from the dictionary table

such as MySQL query the foreign key of a table, you can query the following way

Use INFORMATION_SCHEMA;

Select Table_name,column_name,constraint_name,referenced_table_name,referenced_column_name from KEY_COLUMN_USAGE WHERE table_name = ' logistics_member_express ';

+--------------------------+-----------------+----------------------------+------------------------+----------- -------------+

| table_name | column_name | constraint_name | Referenced_table_name | Referenced_column_name |

+--------------------------+-----------------+----------------------------+------------------------+----------- -------------+

| logistics_member_express | ID | PRIMARY | NULL | NULL |

| logistics_member_express | express_user_id | Reflogistics_express_user6 | Logistics_express_user | ID |

+--------------------------+-----------------+----------------------------+------------------------+----------- -------------+

2 rows in Set (0.00 sec)

You can delete a foreign key if you don't want it:

ALTER TABLE logistics_member_express DROP FOREIGN KEY reflogistics_express_user6;


MySQL queries the foreign key of a table

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.