<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Referential Integrity on SQL Server Scripts</title><link>https://www.sqlserver70.com/tags/referential-integrity/</link><description>Recent content in Referential Integrity on SQL Server Scripts</description><generator>Hugo -- gohugo.io</generator><language>en</language><copyright>SQLServer70.com</copyright><lastBuildDate>Thu, 21 May 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://www.sqlserver70.com/tags/referential-integrity/index.xml" rel="self" type="application/rss+xml"/><item><title>SQL Server List All Foreign Keys with Referenced Tables</title><link>https://www.sqlserver70.com/post/sql-server-list-all-foreign-keys-and-referenced-tables/</link><pubDate>Thu, 21 May 2026 00:00:00 +0000</pubDate><guid>https://www.sqlserver70.com/post/sql-server-list-all-foreign-keys-and-referenced-tables/</guid><description>
&lt;p&gt;Every database with foreign keys eventually needs a single inventory: every constraint, its parent table and column, and the referenced table and column on the other side. This T-SQL script joins &lt;code&gt;sys.foreign_keys&lt;/code&gt; to &lt;code&gt;sys.foreign_key_columns&lt;/code&gt;, &lt;code&gt;sys.tables&lt;/code&gt;, and &lt;code&gt;sys.columns&lt;/code&gt; to produce the canonical foreign-key map of the current database — one row per column in every multi-column foreign key.&lt;/p&gt;
&lt;script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-1012089347386563"
crossorigin="anonymous"&gt;&lt;/script&gt;
&lt;ins class="adsbygoogle"
style="display:inline-block;width:728px;height:90px"
data-ad-client="ca-pub-1012089347386563"
data-ad-slot="8593449130"&gt;&lt;/ins&gt;
&lt;script&gt;
(adsbygoogle = window.adsbygoogle || []).push({});
&lt;/script&gt;
&lt;h2 id="purpose-and-overview"&gt;Purpose and Overview&lt;/h2&gt;
&lt;p&gt;The first symptom that a referential boundary has slipped is usually subtle: a &lt;code&gt;DELETE&lt;/code&gt; on a parent table that ran in seconds last quarter now takes minutes, or a join across the foreign key plans an unexplained scan on the child side. Almost every diagnosis trails back to the same short list — a constraint disabled by an unattended deployment, a NOT TRUSTED flag left behind by a &lt;code&gt;WITH NOCHECK&lt;/code&gt; bulk load, or a duplicate FK shadowing the one the optimizer was relying on. The inventory query below — &lt;code&gt;sys.foreign_keys&lt;/code&gt; joined to &lt;code&gt;sys.foreign_key_columns&lt;/code&gt;, &lt;code&gt;sys.tables&lt;/code&gt;, and &lt;code&gt;sys.columns&lt;/code&gt; — produces the complete relationship map in a single pass, so the foreign key in question is one filter away.&lt;/p&gt;</description></item></channel></rss>