网络营销电子商务研究中心

网络营销电子商务研究中心 (https://www.0058.net/index.php)
-   MySQL (https://www.0058.net/forumdisplay.php?f=76)
-   -   List all tables containing a given column name (https://www.0058.net/showthread.php?t=5386)

Sabine 2015-12-22 04:53 AM

List all tables containing a given column name
 
How do a I list all tables containing a given column name?

I found there are several tables have the same field name, called: product_id.

Any method to find all tables that contain product_id?

Third Lake 2015-12-22 04:56 AM

You can use the INFORMATION_SCHEMA database and the COLUMNS table in particular Example of use:
Code:

SELECT
    table_name,
    column_name,
    data_type,
    ordinal_position

FROM  INFORMATION_SCHEMA.COLUMNS

WHERE table_schema = 'myDatabase'    --- the database you want to search
  AND column_name = 'name' ;          --- or: column_name LIKE '%name%'

say, you want to check a database called cheap_eyeglasses, here is your MySQL command:
Code:

SELECT
    table_name,
    column_name,
    data_type,
    ordinal_position

FROM  INFORMATION_SCHEMA.COLUMNS

WHERE table_schema = 'cheap_eyeglasses'    --- the database you want to search
  AND column_name = 'product_id' ;          --- or: column_name LIKE '%name%'



All times are GMT +8. The time now is 04:06 AM.

Powered by vBulletin Version 3.8.7
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.