2011-01-09 90 views

回答

2

如果你想在一個模式中的所有表和列,無需使用UNION和BIND,只是在

  • INFORMATION_SCHEMA.COLUMNS加入數據
  • INFORMATION_SCHEMA.TABLES

會做的伎倆。見兩個細節在:

http://dev.mysql.com/doc/refman/5.0/en/information-schema.html

一個例子查詢將實現最小的似乎是你的目標應該是:

SELECT TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME 
FROM INFORMATION_SCHEMA.COLUMNS 

但同樣,基於表名連接兩個可能需要 - 取決於你的確切目標。

如果你只是想在名稱UNION/BIND表和名稱中帶有UNION/BIND列,兩個簡單的查詢,這樣做將是:

SELECT TABLE_NAME from INFORMATION_SCHEMA.TABLES 
WHERE TABLE_NAME LIKE '%UNION%' or TABLE_NAME LIKE '%BIND%' 

SELECT TABLE_NAME, COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS 
WHERE COLUMN_NAME LIKE '%UNION%' or TABLE_NAME LIKE '%BIND%' 
+0

謝謝。我不想同時列出所有表格和列,抱歉不清楚。我會再試一次,再次感謝! – qwerty 2011-01-09 20:57:57

0

您可以使用INFORMATION_SCHEMA。下面的查詢將是有益的:

SELECT 'COLUMN' as Match_Type, 
     column_name as MATCH_NAME, 
     table_name, 
     table_schema 
FROM INFORMATION_sCHEMA.COLUMNS 
WHERE COLUMN_NAME LIKE '%UNION%' 
    OR COLUMN_NAME LIKE '%BIND%' 
UNION ALL 
SELECT 'TABLE' as Match_Type, 
     table_name as MATCH_NAME, 
     table_name, 
     table_schema 
FROM INFORMATION_sCHEMA.TABLES 
WHERE TABLE_NAME LIKE '%UNION%' 
    OR TABLE_NAME LIKE '%BIND%'