2012-10-30 9 views

답변

7

당신은 테이블의 전체 정의를 얻으려면

SHOW CREATE TABLE `tablename` 

를 사용할 수 있습니다. 여기에는 모든 외래 키 제약 조건이 포함됩니다.

17

예. 그냥 INFORMATION_SCHEMA

SELECT * FROM information_schema.REFERENTIAL_CONSTRAINTS 

또는 더 구체적으로

-- This query will list all constraints, their delete rule, 
-- the constraint table/column list, and the referenced table 
SELECT 
    r.CONSTRAINT_NAME, 
    r.DELETE_RULE, 
    r.TABLE_NAME, 
    GROUP_CONCAT(k.COLUMN_NAME SEPARATOR ', ') AS `constraint columns`, 
    r.REFERENCED_TABLE_NAME 
FROM information_schema.REFERENTIAL_CONSTRAINTS r 
    JOIN information_schema.KEY_COLUMN_USAGE k 
    USING (CONSTRAINT_CATALOG, CONSTRAINT_SCHEMA, CONSTRAINT_NAME) 
-- using MySQL's GROUP BY clause. In other DB's more columns would need to be 
-- specified! 
GROUP BY r.CONSTRAINT_CATALOG, 
     r.CONSTRAINT_SCHEMA, 
     r.CONSTRAINT_NAME 

REFERENTIAL_CONSTRAINTS table in the manual

에 대한 자세한 읽기를 조회