{"id":465,"date":"2015-01-20T13:38:42","date_gmt":"2015-01-20T13:38:42","guid":{"rendered":"http:\/\/mairwa.com\/wordpress\/?p=465"},"modified":"2015-01-20T13:38:42","modified_gmt":"2015-01-20T13:38:42","slug":"get-all-foreign-key-constraint-from-schema","status":"publish","type":"post","link":"http:\/\/mairwa.com\/wordpress\/?p=465","title":{"rendered":"Get all foreign key constraint from schema"},"content":{"rendered":"<p>SELECT<br \/>\n    K_Table = FK.TABLE_NAME,<br \/>\n    FK_Column = CU.COLUMN_NAME,<br \/>\n    PK_Table = PK.TABLE_NAME,<br \/>\n    PK_Column = PT.COLUMN_NAME,<br \/>\n    Constraint_Name = C.CONSTRAINT_NAME<br \/>\nFROM<br \/>\n    INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS C<br \/>\nINNER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS FK<br \/>\n    ON C.CONSTRAINT_NAME = FK.CONSTRAINT_NAME<br \/>\nINNER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS PK<br \/>\n    ON C.UNIQUE_CONSTRAINT_NAME = PK.CONSTRAINT_NAME<br \/>\nINNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE CU<br \/>\n    ON C.CONSTRAINT_NAME = CU.CONSTRAINT_NAME<br \/>\nINNER JOIN (<br \/>\n            SELECT<br \/>\n                i1.TABLE_NAME,<br \/>\n                i2.COLUMN_NAME<br \/>\n            FROM<br \/>\n                INFORMATION_SCHEMA.TABLE_CONSTRAINTS i1<br \/>\n            INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE i2<br \/>\n                ON i1.CONSTRAINT_NAME = i2.CONSTRAINT_NAME<br \/>\n            WHERE<br \/>\n                i1.CONSTRAINT_TYPE = &#8216;PRIMARY KEY&#8217;<br \/>\n           ) PT<br \/>\n    ON PT.TABLE_NAME = PK.TABLE_NAME<\/p>\n","protected":false},"excerpt":{"rendered":"<p class=\"excerpt\">SELECT K_Table = FK.TABLE_NAME, FK_Column = CU.COLUMN_NAME, PK_Table = PK.TABLE_NAME, PK_Column = PT.COLUMN_NAME, Constraint_Name = C.CONSTRAINT_NAME FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS C INNER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS FK ON C.CONSTRAINT_NAME = FK.CONSTRAINT_NAME INNER JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS PK ON C.UNIQUE_CONSTRAINT_NAME = PK.CONSTRAINT_NAME INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE CU ON C.CONSTRAINT_NAME = CU.CONSTRAINT_NAME INNER JOIN ( SELECT i1.TABLE_NAME, i2.COLUMN_NAME FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS i1 INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE i2 ON i1.CONSTRAINT_NAME = i2.CONSTRAINT_NAME&hellip; <a href=\"http:\/\/mairwa.com\/wordpress\/?p=465\">Read more &rarr;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-465","post","type-post","status-publish","format-standard","hentry","category-c-vb","xfolkentry"],"_links":{"self":[{"href":"http:\/\/mairwa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/465","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/mairwa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/mairwa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/mairwa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/mairwa.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=465"}],"version-history":[{"count":0,"href":"http:\/\/mairwa.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/465\/revisions"}],"wp:attachment":[{"href":"http:\/\/mairwa.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=465"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/mairwa.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=465"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/mairwa.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=465"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}