{"id":40,"date":"2010-09-23T15:18:05","date_gmt":"2010-09-23T22:18:05","guid":{"rendered":"http:\/\/www.sqldbpros.com\/?p=40"},"modified":"2010-10-01T12:35:58","modified_gmt":"2010-10-01T19:35:58","slug":"finding-sql-server-foreign-keys-the-fast-way","status":"publish","type":"post","link":"http:\/\/sqldbpros.com\/wordpress\/2010\/09\/finding-sql-server-foreign-keys-the-fast-way\/","title":{"rendered":"Finding SQL Server Foreign Keys &#8211; The fast way"},"content":{"rendered":"<p>There are a dozen different ways to find the foreign keys in an MS SQL database.\u00a0 You can make it as hard on yourself as you want or as time consuming as your boss will allow.\u00a0 SQL Server consultants turn to the following T-SQL script to get a list of SQL Server Foreign Keys as quickly and efficiently as possible:<!--more--><\/p>\n<blockquote><p>SELECT<br \/>\nOBJECT_SCHEMA_NAME(parent_object_id) ParentSchema<br \/>\n,OBJECT_NAME(parent_object_id) ParentTable<br \/>\n,OBJECT_SCHEMA_NAME(referenced_object_id) ChildSchema<br \/>\n,OBJECT_NAME(referenced_object_id) ChildTable<br \/>\n,name FKName<br \/>\n,object_id<br \/>\n,is_disabled<br \/>\n,is_not_for_replication<br \/>\n,is_not_trusted<br \/>\n,delete_referential_action<br \/>\n,update_referential_action<br \/>\nFROM<br \/>\nsys.foreign_keys<br \/>\nORDER BY<br \/>\n1<br \/>\n,2<br \/>\n,3<br \/>\n,4<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Need a list of Foreign Keys in your database.  This simple query will deliver quickly and efficiently.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-40","post","type-post","status-publish","format-standard","hentry","category-scripts"],"_links":{"self":[{"href":"http:\/\/sqldbpros.com\/wordpress\/wp-json\/wp\/v2\/posts\/40","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/sqldbpros.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/sqldbpros.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/sqldbpros.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/sqldbpros.com\/wordpress\/wp-json\/wp\/v2\/comments?post=40"}],"version-history":[{"count":5,"href":"http:\/\/sqldbpros.com\/wordpress\/wp-json\/wp\/v2\/posts\/40\/revisions"}],"predecessor-version":[{"id":44,"href":"http:\/\/sqldbpros.com\/wordpress\/wp-json\/wp\/v2\/posts\/40\/revisions\/44"}],"wp:attachment":[{"href":"http:\/\/sqldbpros.com\/wordpress\/wp-json\/wp\/v2\/media?parent=40"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/sqldbpros.com\/wordpress\/wp-json\/wp\/v2\/categories?post=40"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/sqldbpros.com\/wordpress\/wp-json\/wp\/v2\/tags?post=40"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}