0
所有列名稱我有選擇的所有列名的MySql的select
查詢:選擇從MySQL數據庫
SELECT info.COLUMN_NAME AS `NAME`, info.TABLE_SCHEMA AS `TABLESCHEMA`,
info.TABLE_NAME AS `TABLENAME`, info.ORDINAL_POSITION AS `POSITION`,
info.IS_NULLABLE AS `ISNULLABLE`, info.DATA_TYPE AS `DATATYPE`,
tc.CONSTRAINT_TYPE AS `CONSTRAINTTYPE`,
kcufk.TABLE_SCHEMA AS `REFRENCESCHEMA`,
kcufk.TABLE_NAME AS `REFRENCETABLE`,
kcufk.COLUMN_NAME AS `REFRENCECOLUMN` FROM
INFORMATION_SCHEMA.`COLUMNS` info LEFT OUTER JOIN INFORMATION_SCHEMA.`KEY_COLUMN_USAGE` kcu
ON kcu.COLUMN_NAME = info.COLUMN_NAME AND kcu.TABLE_NAME = info.TABLE_NAME LEFT OUTER JOIN
INFORMATION_SCHEMA.`TABLE_CONSTRAINTS` tc ON tc.CONSTRAINT_NAME = kcu.CONSTRAINT_NAME
AND tc.TABLE_NAME = kcu.TABLE_NAME LEFT OUTER JOIN INFORMATION_SCHEMA.`REFERENTIAL_CONSTRAINTS`
rk ON rk.CONSTRAINT_NAME = tc.CONSTRAINT_NAME LEFT OUTER JOIN INFORMATION_SCHEMA.`KEY_COLUMN_USAGE`
kcufk ON kcufk.CONSTRAINT_NAME = rk.UNIQUE_CONSTRAINT_NAME WHERE info.TABLE_NAME = 'reportsetting' AND
info.TABLE_SCHEMA = 'core' ORDER BY info.ORDINAL_POSITION ASC
的問題是在執行這個查詢,外鍵來了多次。
What am I doing wrong in this query?
: - 在執行這個查詢O/P來一次,但其REFRENCETABLE沒有顯示正確。它顯示相同的表名,即報告設置 – Sanjiv
: - 即使'REFRENCECOLUMN'也不能正確顯示。它顯示相同的表引用列名 – Sanjiv
我得到了解決方案..其實我選擇table_name而不是reference_table_name。 – Sanjiv