<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>foreign key &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/foreign-key/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.dbrnd.com</link>
	<description>BIGData &#124; NoSQL &#124; MSSQL &#124; MySQL &#124; PostgreSQL</description>
	<lastBuildDate>Mon, 24 Jun 2019 19:42:10 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.4</generator>
	<item>
		<title>SQL Server: How to compare your objects between two Databases</title>
		<link>https://www.dbrnd.com/2019/08/sql-server-how-to-compare-your-objects-table-view-stored-procedure-trigger-constraint-between-two-databases/</link>
					<comments>https://www.dbrnd.com/2019/08/sql-server-how-to-compare-your-objects-table-view-stored-procedure-trigger-constraint-between-two-databases/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 05 Aug 2019 16:16:04 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server DBA Script]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[compare]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[foreign key]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[Primary key]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tunning]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[stored procedures]]></category>
		<category><![CDATA[tables]]></category>
		<category><![CDATA[trigger]]></category>
		<category><![CDATA[TSQL]]></category>
		<category><![CDATA[views]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=4094</guid>

					<description><![CDATA[When we are working with different versions of database, database professionals are comparing the objects between databases of SQL Server. They must make sure about that all databases are in sync. Using this T-SQL Script, you can compare two databases and find a list of unmatched objects like: Constraints, Tables, Views, Stored Procedure, Triggers. Sample [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F08%2Fsql-server-how-to-compare-your-objects-table-view-stored-procedure-trigger-constraint-between-two-databases%2F&amp;linkname=SQL%20Server%3A%20How%20to%20compare%20your%20objects%20between%20two%20Databases" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F08%2Fsql-server-how-to-compare-your-objects-table-view-stored-procedure-trigger-constraint-between-two-databases%2F&amp;linkname=SQL%20Server%3A%20How%20to%20compare%20your%20objects%20between%20two%20Databases" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F08%2Fsql-server-how-to-compare-your-objects-table-view-stored-procedure-trigger-constraint-between-two-databases%2F&amp;linkname=SQL%20Server%3A%20How%20to%20compare%20your%20objects%20between%20two%20Databases" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F08%2Fsql-server-how-to-compare-your-objects-table-view-stored-procedure-trigger-constraint-between-two-databases%2F&amp;linkname=SQL%20Server%3A%20How%20to%20compare%20your%20objects%20between%20two%20Databases" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F08%2Fsql-server-how-to-compare-your-objects-table-view-stored-procedure-trigger-constraint-between-two-databases%2F&amp;linkname=SQL%20Server%3A%20How%20to%20compare%20your%20objects%20between%20two%20Databases" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F08%2Fsql-server-how-to-compare-your-objects-table-view-stored-procedure-trigger-constraint-between-two-databases%2F&amp;linkname=SQL%20Server%3A%20How%20to%20compare%20your%20objects%20between%20two%20Databases" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F08%2Fsql-server-how-to-compare-your-objects-table-view-stored-procedure-trigger-constraint-between-two-databases%2F&#038;title=SQL%20Server%3A%20How%20to%20compare%20your%20objects%20between%20two%20Databases" data-a2a-url="https://www.dbrnd.com/2019/08/sql-server-how-to-compare-your-objects-table-view-stored-procedure-trigger-constraint-between-two-databases/" data-a2a-title="SQL Server: How to compare your objects between two Databases"></a></p><p>When we are working with different versions of database, database professionals are comparing the objects between databases of SQL Server.<br />
They must make sure about that all databases are in sync. </p>
<blockquote><p>Using this T-SQL Script, you can compare two databases and find a list of unmatched objects like: Constraints, Tables, Views, Stored Procedure, Triggers. </p></blockquote>
<p><strong>Sample demonstration:</strong><br />
<strong>First, Create two sample databases:<br />
</strong></p>
<pre class="crayon-plain-tag">CREATE DATABASE ABC
GO
CREATE DATABASE XYZ
GO</pre> </p>
<p><strong>Create few sample tables in both the databases:<br />
</strong></p><pre class="crayon-plain-tag">CREATE TABLE ABC.dbo.tbl_Test
(
	ID INT
	,MyDate DATE
)
GO

CREATE TABLE ABC.dbo.tbl_MyTest
(
	ID INT
	,Name VARCHAR(50)
)
GO

CREATE TABLE XYZ.dbo.tbl_Test
(
	ID INT
	,MyDate DATE
)
GO

CREATE TABLE XYZ.dbo.tbl_MyFinal
(
	ID INT
	,Name VARCHAR(50)
)
GO</pre><p> </p>
<p><strong>T-SQL Script to compare objects between two databases:</strong><br />
According to your databases, You can change the name of @SourceDatabase and @DestinationDatabase.</p>
<pre class="crayon-plain-tag">DECLARE @SourceDatabase VARCHAR(50) 
DECLARE @DestinationDatabase VARCHAR(50) 
DECLARE @SQL VARCHAR(MAX) 
     
SELECT @SourceDatabase = 'ABC' 
SELECT @DestinationDatabase = 'XYZ'
     
SELECT @SQL = 
'
	SELECT 
		ISNULL(S.name,D.name) ObjectName
		,CASE  
			WHEN S.object_id IS NULL 
				THEN D.type_desc + '' is missing in the Source Database: '	+ @SourceDatabase + ''' 
			WHEN D.object_id IS NULL 
				THEN S.type_desc +  '' is missing in the Destination Database: ' + @DestinationDatabase + ''' 
		END ''Status'' 
	FROM 
	(
		SELECT * FROM ' + @SourceDatabase + '.SYS.objects  
		WHERE Type_desc not in (''INTERNAL_TABLE'',''SYSTEM_TABLE'',''SERVICE_QUEUE'')
	) AS S  
	FULL OUTER JOIN 
	(
		SELECT * FROM ' + @DestinationDatabase + '.SYS.objects  
		WHERE Type_desc not in (''INTERNAL_TABLE'',''SYSTEM_TABLE'',''SERVICE_QUEUE'')
	) AS D 
	ON S.name = D.name 
		AND S.type = D.type 
	ORDER BY isnull(S.type,D.type)
'  
EXEC (@Sql)</pre> </p>
<p><strong>The Result:</strong></p>
<pre class="crayon-plain-tag">ObjectName                         Status
------------------  -------------------------------------------------------
tbl_Test              NULL
tbl_MyFinal           USER_TABLE is missing in the Source Database: ABC
tbl_MyTest            USER_TABLE is missing in the Destination Database: XYZ</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2019/08/sql-server-how-to-compare-your-objects-table-view-stored-procedure-trigger-constraint-between-two-databases/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>SQL Server: Script to find untrusted or invalid Foreign Keys</title>
		<link>https://www.dbrnd.com/2017/09/sql-server-script-to-find-untrusted-or-invalid-foreign-keys/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Fri, 01 Sep 2017 16:16:09 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server DBA Script]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[foreign key]]></category>
		<category><![CDATA[Foreign Key constraint]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Error]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tuning]]></category>
		<category><![CDATA[SQL Server Programming]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=6011</guid>

					<description><![CDATA[I already shared an article on how to enable or disable the foreign keys in the SQL Server. Enable and Disable Foreign key and Check constraint in SQL Server Why we require this? To make faster data migration by disabling the foreign key constraint. For example, Now foreign key constraint disabled, and you load/migrate the [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F09%2Fsql-server-script-to-find-untrusted-or-invalid-foreign-keys%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20untrusted%20or%20invalid%20Foreign%20Keys" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F09%2Fsql-server-script-to-find-untrusted-or-invalid-foreign-keys%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20untrusted%20or%20invalid%20Foreign%20Keys" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F09%2Fsql-server-script-to-find-untrusted-or-invalid-foreign-keys%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20untrusted%20or%20invalid%20Foreign%20Keys" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F09%2Fsql-server-script-to-find-untrusted-or-invalid-foreign-keys%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20untrusted%20or%20invalid%20Foreign%20Keys" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F09%2Fsql-server-script-to-find-untrusted-or-invalid-foreign-keys%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20untrusted%20or%20invalid%20Foreign%20Keys" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F09%2Fsql-server-script-to-find-untrusted-or-invalid-foreign-keys%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20untrusted%20or%20invalid%20Foreign%20Keys" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F09%2Fsql-server-script-to-find-untrusted-or-invalid-foreign-keys%2F&#038;title=SQL%20Server%3A%20Script%20to%20find%20untrusted%20or%20invalid%20Foreign%20Keys" data-a2a-url="https://www.dbrnd.com/2017/09/sql-server-script-to-find-untrusted-or-invalid-foreign-keys/" data-a2a-title="SQL Server: Script to find untrusted or invalid Foreign Keys"></a></p><p>I already shared an article on how to enable or disable the foreign keys in the SQL Server.</p>
<blockquote data-secret="dSdov48YjQ" class="wp-embedded-content"><p><a href="https://www.dbrnd.com/2015/09/enable-disable-foreign-key-and-check-constraint-in-sql-server/">Enable and Disable Foreign key and Check constraint in SQL Server</a></p></blockquote>
<p><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2015/09/enable-disable-foreign-key-and-check-constraint-in-sql-server/embed/#?secret=dSdov48YjQ" data-secret="dSdov48YjQ" width="600" height="338" title="&#8220;Enable and Disable Foreign key and Check constraint in SQL Server&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<p>Why we require this? To make faster data migration by disabling the foreign key constraint.</p>
<blockquote><p>For example, Now foreign key constraint disabled, and you load/migrate the data. Next, you enable the foreign key constraint with NOCHECK option.</p>
<p>That means if your key data do not reference of your primary key then also it allows the foreign key constraint that is called untrusted or invalid foreign key constraint because data is invalid. </p></blockquote>
<p><em>You must find out untrusted or invalid foreign keys from your SQL Server so that you can take appropriate action on invalid referenced data.</em></p>
<p><strong>Use below script to find untrusted or invalid foregin keys:</strong></p>
<pre class="crayon-plain-tag">SELECT '[' + s.name + '].[' + o.name + '].[' + f.name + ']' AS ForeignKeyName
FROM    sys.foreign_keys f
INNER JOIN sys.objects o 
	ON f.parent_object_id = o.object_id
INNER JOIN sys.schemas s 
	ON o.schema_id = s.schema_id
WHERE   f.is_not_trusted = 1
	AND f.is_not_for_replication = 0
	AND f.is_disabled = 0</pre> </p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>SQL Server 2016: Create a FOREIGN KEY in Memory optimized Table (In-Memory OLTP)</title>
		<link>https://www.dbrnd.com/2017/02/sql-server-2016-create-a-foreign-key-in-memory-optimized-table-in-memory-oltp/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Thu, 23 Feb 2017 16:16:23 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[foreign key]]></category>
		<category><![CDATA[Hekaton]]></category>
		<category><![CDATA[In-Memory OLTP]]></category>
		<category><![CDATA[Memory Optimized Table]]></category>
		<category><![CDATA[MEMORY_OPTIMIZED_DATA]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server 2014]]></category>
		<category><![CDATA[SQL Server 2016]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Error]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tuning]]></category>
		<category><![CDATA[SQL Server Programming]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=4619</guid>

					<description><![CDATA[If you don&#8217;t know about the Hekaton engine of SQL Server 2014, please visit below an article. SQL Server 2014: What is Hekaton? I am very surprised with the feature list of SQL Server 2016 because it came with lots of features and improvements. Whenever I explored SQL Server 2016, I got something new. SQL [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F02%2Fsql-server-2016-create-a-foreign-key-in-memory-optimized-table-in-memory-oltp%2F&amp;linkname=SQL%20Server%202016%3A%20Create%20a%20FOREIGN%20KEY%20in%20Memory%20optimized%20Table%20%28In-Memory%20OLTP%29" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F02%2Fsql-server-2016-create-a-foreign-key-in-memory-optimized-table-in-memory-oltp%2F&amp;linkname=SQL%20Server%202016%3A%20Create%20a%20FOREIGN%20KEY%20in%20Memory%20optimized%20Table%20%28In-Memory%20OLTP%29" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F02%2Fsql-server-2016-create-a-foreign-key-in-memory-optimized-table-in-memory-oltp%2F&amp;linkname=SQL%20Server%202016%3A%20Create%20a%20FOREIGN%20KEY%20in%20Memory%20optimized%20Table%20%28In-Memory%20OLTP%29" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F02%2Fsql-server-2016-create-a-foreign-key-in-memory-optimized-table-in-memory-oltp%2F&amp;linkname=SQL%20Server%202016%3A%20Create%20a%20FOREIGN%20KEY%20in%20Memory%20optimized%20Table%20%28In-Memory%20OLTP%29" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F02%2Fsql-server-2016-create-a-foreign-key-in-memory-optimized-table-in-memory-oltp%2F&amp;linkname=SQL%20Server%202016%3A%20Create%20a%20FOREIGN%20KEY%20in%20Memory%20optimized%20Table%20%28In-Memory%20OLTP%29" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F02%2Fsql-server-2016-create-a-foreign-key-in-memory-optimized-table-in-memory-oltp%2F&amp;linkname=SQL%20Server%202016%3A%20Create%20a%20FOREIGN%20KEY%20in%20Memory%20optimized%20Table%20%28In-Memory%20OLTP%29" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F02%2Fsql-server-2016-create-a-foreign-key-in-memory-optimized-table-in-memory-oltp%2F&#038;title=SQL%20Server%202016%3A%20Create%20a%20FOREIGN%20KEY%20in%20Memory%20optimized%20Table%20%28In-Memory%20OLTP%29" data-a2a-url="https://www.dbrnd.com/2017/02/sql-server-2016-create-a-foreign-key-in-memory-optimized-table-in-memory-oltp/" data-a2a-title="SQL Server 2016: Create a FOREIGN KEY in Memory optimized Table (In-Memory OLTP)"></a></p><p>If you don&#8217;t know about the Hekaton engine of SQL Server 2014, please visit below an article.</p>
<blockquote class="wp-embedded-content" data-secret="2OEobqI4m5"><p><a href="https://www.dbrnd.com/2016/01/sql-server-2014-what-is-hekaton/">SQL Server 2014: What is Hekaton?</a></p></blockquote>
<p><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/01/sql-server-2014-what-is-hekaton/embed/#?secret=2OEobqI4m5" data-secret="2OEobqI4m5" width="600" height="338" title="&#8220;SQL Server 2014: What is Hekaton?&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<blockquote><p>I am very surprised with the feature list of SQL Server 2016 because it came with lots of features and improvements. Whenever I explored SQL Server 2016, I got something new.<br />
SQL Server 2016 already enhanced In-Memory OLTP by introducing the list of features. Let me share one of the features here.</p></blockquote>
<p>In the previous version, you cannot create a FOREIGN KEY in memory optimized table. Now, SQL Server 2016 introduced a feature to store the reference of a table in memory so you can create a FOREIGN KEY in memory optimized tables.</p>
<blockquote><p>You can create a reference between memory optimized tables; you cannot give reference of a Non-memory optimized table to a memory optimized table.</p></blockquote>
<p>Below is a full demonstration on this.</p>
<p>If you do not configure Memory optimized file group and data file, use below script to configure it.</p>
<p><strong>Add Memory optimized file group:</strong></p>
<pre class="crayon-plain-tag">ALTER DATABASE Database_Name
ADD Filegroup OLTP_InMemory CONTAINS MEMORY_OPTIMIZED_DATA</pre> </p>
<p><strong>Add data file into created Memory optimized file group:</strong></p>
<pre class="crayon-plain-tag">ALTER DATABASE Database_Name
ADD FILE (NAME = OLTP_InMemory, FILENAME = N'C:\SQLBackup\Hekaton')
TO FILEGROUP OLTP_InMemory</pre> </p>
<p><strong>Create a sample In-Memory table:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE tbl_Departments
(
	DeptID INT PRIMARY KEY NONCLUSTERED
	,DeptName VARCHAR(20)	
)WITH ( MEMORY_OPTIMIZED = ON, DURABILITY = SCHEMA_AND_DATA)
GO</pre> </p>
<p><strong>Create a another In-Memory child table:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE tbl_Employee
(
	EmpID INT PRIMARY KEY NONCLUSTERED
	,EmpName VARCHAR(20)
	,DeptID INT
	,CONSTRAINT fk_tbl_Employee_EmpID FOREIGN KEY (DeptID) REFERENCES tbl_Departments(DeptID)
) WITH ( MEMORY_OPTIMIZED = ON, DURABILITY = SCHEMA_AND_DATA);
GO</pre> </p>
<p><strong>Try to give reference of Non-Memory optimized table to Memory optimized table:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE tbl_EmpSalary
(
	EmpSalaryID INT PRIMARY KEY 
	,EmpID INT
	,EmpSalary INT
	,EmpSalaryMonth INT
	,CONSTRAINT fk_tbl_EmpSalary_EmpID FOREIGN KEY (EmpID) REFERENCES tbl_Employee(EmpID)
)
GO</pre> </p>
<p><strong>You will get below errors:</strong></p>
<pre class="crayon-plain-tag">Msg 10778, Level 16, State 0, Line 1
Foreign key relationships between memory optimized tables and non-memory optimized tables are not supported.
Msg 1750, Level 16, State 1, Line 1
Could not create constraint or index. See previous errors.</pre> </p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>SQL Server: Script to find disable foreign key tables</title>
		<link>https://www.dbrnd.com/2016/11/sql-server-script-to-find-disable-constraint-foreign-key-tables/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Tue, 01 Nov 2016 16:16:29 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server DBA Script]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[disable constraint]]></category>
		<category><![CDATA[foreign key]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tunning]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=3412</guid>

					<description><![CDATA[In this post, I am going to share one of the important script for SQL Serve DBA to find a list of tables which have disable foreign keys. In any RDBMS system, the rule of data integrity is mandatory because it ensures the quality of data. In our organization, database developers sometime disable the foreign [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F11%2Fsql-server-script-to-find-disable-constraint-foreign-key-tables%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20disable%20foreign%20key%20tables" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F11%2Fsql-server-script-to-find-disable-constraint-foreign-key-tables%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20disable%20foreign%20key%20tables" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F11%2Fsql-server-script-to-find-disable-constraint-foreign-key-tables%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20disable%20foreign%20key%20tables" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F11%2Fsql-server-script-to-find-disable-constraint-foreign-key-tables%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20disable%20foreign%20key%20tables" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F11%2Fsql-server-script-to-find-disable-constraint-foreign-key-tables%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20disable%20foreign%20key%20tables" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F11%2Fsql-server-script-to-find-disable-constraint-foreign-key-tables%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20disable%20foreign%20key%20tables" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F11%2Fsql-server-script-to-find-disable-constraint-foreign-key-tables%2F&#038;title=SQL%20Server%3A%20Script%20to%20find%20disable%20foreign%20key%20tables" data-a2a-url="https://www.dbrnd.com/2016/11/sql-server-script-to-find-disable-constraint-foreign-key-tables/" data-a2a-title="SQL Server: Script to find disable foreign key tables"></a></p><p>In this post, I am going to share one of the important script for SQL Serve DBA to find a list of tables which have disable foreign keys. </p>
<blockquote><p>In any RDBMS system, the rule of data integrity is mandatory because it ensures the quality of data. </p></blockquote>
<blockquote><p>In our organization, database developers sometime disable the foreign key constraint because they required to insert test data or required to import non-related data.<br />
After this testing, there are 90% chance of forgetting to enable foreign key constraint again to maintain further data integrity.</p></blockquote>
<p>Using below script,the DBA can find a list of tables which have disable foreign key constraints.</p>
<pre class="crayon-plain-tag">SELECT 
	[s].[name] + '.' + [t].[name] AS TableName
FROM [sys].[tables] AS t
INNER JOIN [sys].[schemas] AS s
	ON [t].[schema_id] = [s].[schema_id]
WHERE EXISTS
(
	SELECT 1 FROM [sys].[foreign_keys] AS fk
	WHERE [fk].[parent_object_id] = [t].[object_id]
		AND [fk].[is_disabled] = 1
);</pre> </p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>SQL Server: Database Developer (T-SQL) Interview Questions and Answers (Day-2)</title>
		<link>https://www.dbrnd.com/2016/06/sql-server-database-developer-t-sql-interview-questions-and-answers-primary-unique-foregin-super-natural-surrogate-candidate-composite-key-normalization-day-2/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 13 Jun 2016 19:27:38 +0000</pubDate>
				<category><![CDATA[SQL Server Interview]]></category>
		<category><![CDATA[answers]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[composite key]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[Database Developer]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[discard query result]]></category>
		<category><![CDATA[foreign key]]></category>
		<category><![CDATA[Interviews]]></category>
		<category><![CDATA[natural key]]></category>
		<category><![CDATA[Primary key]]></category>
		<category><![CDATA[questions]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tunning]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[TSQL]]></category>
		<category><![CDATA[unique key]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=3035</guid>

					<description><![CDATA[What are the different main type of normalization? In database design, we start with one single table, with all possible columns. A lot of redundant data would be present since it’s a single table. The process of removing the redundant data, by splitting up the table in a well defined fashion is called normalization. First [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F06%2Fsql-server-database-developer-t-sql-interview-questions-and-answers-primary-unique-foregin-super-natural-surrogate-candidate-composite-key-normalization-day-2%2F&amp;linkname=SQL%20Server%3A%20Database%20Developer%20%28T-SQL%29%20Interview%20Questions%20and%20Answers%20%28Day-2%29" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F06%2Fsql-server-database-developer-t-sql-interview-questions-and-answers-primary-unique-foregin-super-natural-surrogate-candidate-composite-key-normalization-day-2%2F&amp;linkname=SQL%20Server%3A%20Database%20Developer%20%28T-SQL%29%20Interview%20Questions%20and%20Answers%20%28Day-2%29" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F06%2Fsql-server-database-developer-t-sql-interview-questions-and-answers-primary-unique-foregin-super-natural-surrogate-candidate-composite-key-normalization-day-2%2F&amp;linkname=SQL%20Server%3A%20Database%20Developer%20%28T-SQL%29%20Interview%20Questions%20and%20Answers%20%28Day-2%29" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F06%2Fsql-server-database-developer-t-sql-interview-questions-and-answers-primary-unique-foregin-super-natural-surrogate-candidate-composite-key-normalization-day-2%2F&amp;linkname=SQL%20Server%3A%20Database%20Developer%20%28T-SQL%29%20Interview%20Questions%20and%20Answers%20%28Day-2%29" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F06%2Fsql-server-database-developer-t-sql-interview-questions-and-answers-primary-unique-foregin-super-natural-surrogate-candidate-composite-key-normalization-day-2%2F&amp;linkname=SQL%20Server%3A%20Database%20Developer%20%28T-SQL%29%20Interview%20Questions%20and%20Answers%20%28Day-2%29" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F06%2Fsql-server-database-developer-t-sql-interview-questions-and-answers-primary-unique-foregin-super-natural-surrogate-candidate-composite-key-normalization-day-2%2F&amp;linkname=SQL%20Server%3A%20Database%20Developer%20%28T-SQL%29%20Interview%20Questions%20and%20Answers%20%28Day-2%29" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F06%2Fsql-server-database-developer-t-sql-interview-questions-and-answers-primary-unique-foregin-super-natural-surrogate-candidate-composite-key-normalization-day-2%2F&#038;title=SQL%20Server%3A%20Database%20Developer%20%28T-SQL%29%20Interview%20Questions%20and%20Answers%20%28Day-2%29" data-a2a-url="https://www.dbrnd.com/2016/06/sql-server-database-developer-t-sql-interview-questions-and-answers-primary-unique-foregin-super-natural-surrogate-candidate-composite-key-normalization-day-2/" data-a2a-title="SQL Server: Database Developer (T-SQL) Interview Questions and Answers (Day-2)"></a></p><p><strong>What are the different main type of normalization?</strong></p>
<blockquote><p>In database design, we start with one single table, with all possible columns. A lot of redundant data would be present since it’s a single table. The process of removing the redundant data, by splitting up the table in a well defined fashion is called normalization.</p>
<p><strong>First Normal Form (1NF):</strong>A relation is said to be in first normal form if and only if all underlying domains contain atomic values only. After 1NF, we can still have redundant data.</p>
<p><strong>Second Normal Form (2NF):</strong>A relation is said to be in 2NF if and only if it is in 1NF and every non key attribute is fully dependent on the primary key. After 2NF, we can still have redundant data.</p>
<p><strong>Third Normal Form (3NF):</strong>A relation is said to be in 3NF, if and only if it is in 2NF and every non key attribute is non-transitively dependent on the primary key.</p></blockquote>
<p><strong>What is the Primary key?</strong></p>
<blockquote><p>A primary key is a one or more fields that uniquely identifies a row in a table. The primary key cannot be null (blank). The primary key is indexed.</p>
<p>A primary key is a value that can be used to identify a unique row in a table.</p></blockquote>
<p><strong>What should be your best practice with Primary Key?</strong></p>
<blockquote class="wp-embedded-content" data-secret="9NktFhZ1G1"><p><a href="https://www.dbrnd.com/2015/09/best-practice-for-primary-key-in-database-management-system/">Best practice for Primary Key in Database Management System</a></p></blockquote>
<p><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2015/09/best-practice-for-primary-key-in-database-management-system/embed/#?secret=9NktFhZ1G1" data-secret="9NktFhZ1G1" width="600" height="338" title="&#8220;Best practice for Primary Key in Database Management System&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<p><strong>How to find all the Tables without having a Primary Key?</strong></p>
<blockquote class="wp-embedded-content" data-secret="9xi49k8KqF"><p><a href="https://www.dbrnd.com/2016/01/sql-server-script-to-find-all-the-tables-without-having-a-primary-key/">SQL Server: Script to find all the Tables without having a Primary Key</a></p></blockquote>
<p><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/01/sql-server-script-to-find-all-the-tables-without-having-a-primary-key/embed/#?secret=9xi49k8KqF" data-secret="9xi49k8KqF" width="600" height="338" title="&#8220;SQL Server: Script to find all the Tables without having a Primary Key&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<p><strong>What is the Unique key?</strong></p>
<blockquote><p>Unique key also ensures data uniqueness like primary key.</p>
<p>A column with unique key defined allows null value. By default, it creates non-clustered index.</p></blockquote>
<p><strong>What is the Super key?</strong></p>
<blockquote><p>A superkey is defined in the relational model as a set of attributes of a relation variable (relvar) for which it holds that in all relations assigned to that variable there are no two distinct tuples (rows) that have the same values for the attributes in this set. Equivalently a superkey can also be defined as a set of attributes of a relvar upon which all attributes of the relvar are functionally dependent.</p></blockquote>
<p><strong>What is the Foreign key?</strong></p>
<blockquote><p> A foreign key is a relationship between columns in two database tables (one of which is indexed) designed to insure consistency of data.</p>
<p>Usually a foreign key in one table refers to the primary key (PK) of another table. This way references can be made to link information together and it is an essential part of database normalization.</p></blockquote>
<p><strong>How to Find Foreign key References in SQL Server?</strong></p>
<blockquote class="wp-embedded-content" data-secret="JBYQPgMqrd"><p><a href="https://www.dbrnd.com/2015/06/find-foreign-key-reference-source-target-in-sql-server/">How to Find Foreign key References in SQL Server</a></p></blockquote>
<p><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2015/06/find-foreign-key-reference-source-target-in-sql-server/embed/#?secret=JBYQPgMqrd" data-secret="JBYQPgMqrd" width="600" height="338" title="&#8220;How to Find Foreign key References in SQL Server&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<p><strong>How you can find source and destination information of all foreign keys?</strong></p>
<blockquote class="wp-embedded-content" data-secret="aR1cKvqKP8"><p><a href="https://www.dbrnd.com/2015/10/postgresql-script-to-find-source-and-destination-of-all-foreign-key-constraint/">PostgreSQL: Script to find Source and Destination of All Foreign Key Constraint</a></p></blockquote>
<p><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2015/10/postgresql-script-to-find-source-and-destination-of-all-foreign-key-constraint/embed/#?secret=aR1cKvqKP8" data-secret="aR1cKvqKP8" width="600" height="338" title="&#8220;PostgreSQL: Script to find Source and Destination of All Foreign Key Constraint&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<p><strong>What is the Composite key?</strong></p>
<blockquote><p>A composite key consists of more than one field to uniquely identify a record. This differs from a compound key in that one or more of the attributes, which make up the key, are not simple keys in their own right. Taking the example from compound key, imagine we identified a student by their firstName + lastName.</p>
<p>In our table representing students on modules our primary key would now be firstName + lastName + moduleCode. Because firstName + lastName represent a unique reference to a student, they are not each simple keys, they have to be combined in order to uniquely identify the student. Therefore the key for this table is a composite key.</p></blockquote>
<p><strong>What is the Natural key?</strong></p>
<blockquote><p>A composite primary key which is composed of attributes (fields) which already exist in the real world e.g. First Name, Last Name, Social Security Number.</p></blockquote>
<p><strong>What is the Surrogate key?</strong></p>
<blockquote><p>A primary key which is internally generated (typically auto-incremental integer value) that does not exist in the real world i.e. ID=1 for Customer A and ID=2 for Customer B serves to uniquely identify the record but has no bearing the customer themselves and is an attribute they will never (need to) be aware of.</p></blockquote>
<p><strong>What is the Candidate key?</strong></p>
<blockquote><p>A candidate key is a column or group of columns that can uniquely identify a row in the table without referring to any other source.</p></blockquote>
<p><strong>What is the Compound key?</strong></p>
<blockquote><p> A composite key consisting of two or more fields that uniquely describe a row in a table. The difference between compound and candidate is that all of the fields in the compound key are foreign keys; in the candidate key one or more of the fields may be foreign keys.</p></blockquote>
<p><strong>Can a foreign key reference a non-primary key?</strong></p>
<blockquote><p>Yes, a foreign key can actually reference a key that is not the primary key of a table. But, a foreign key must reference a unique key.</p></blockquote>
<p><strong>Can a foreign key contain null values?</strong></p>
<blockquote><p>Yes, a foreign key can hold NULL values. Because foreign keys can reference unique, non-primary keys – which can hold NULL values – this means that foreign keys can themselves hold NULL values as well.</p></blockquote>
<p><strong>What are the type of data integrity?</strong></p>
<ul>
<li>Domain Integrity: data type, check constraints</li>
<li>Entity Integrity: primary key, unique constraint</li>
<li>Referential Integrity: foreign key constraint</li>
</ul>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>MySQL: Error code 1005 Can’t create table (errno 150)</title>
		<link>https://www.dbrnd.com/2016/05/mysql-error-code-1005-cant-create-table-errno-150/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Thu, 12 May 2016 19:56:17 +0000</pubDate>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[foreign key]]></category>
		<category><![CDATA[MySQL Command]]></category>
		<category><![CDATA[MySQL Database Administrator]]></category>
		<category><![CDATA[MySQL Database Designing]]></category>
		<category><![CDATA[MySQL Database Programming]]></category>
		<category><![CDATA[MySQL Error]]></category>
		<category><![CDATA[MySQL Performance Tunning]]></category>
		<category><![CDATA[MySQL Query]]></category>
		<category><![CDATA[MySQL Tips and Tricks]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=2793</guid>

					<description><![CDATA[MySQL Error code: 1005 Can’t create table (errno 150). This error message is a pretty frustrating because it is not properly well-defined error message. I have got this message while creating a table with foreign key constraint. I checked syntax and other things which were also correct. This error looks like an OS file permission [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F05%2Fmysql-error-code-1005-cant-create-table-errno-150%2F&amp;linkname=MySQL%3A%20Error%20code%201005%20Can%E2%80%99t%20create%20table%20%28errno%20150%29" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F05%2Fmysql-error-code-1005-cant-create-table-errno-150%2F&amp;linkname=MySQL%3A%20Error%20code%201005%20Can%E2%80%99t%20create%20table%20%28errno%20150%29" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F05%2Fmysql-error-code-1005-cant-create-table-errno-150%2F&amp;linkname=MySQL%3A%20Error%20code%201005%20Can%E2%80%99t%20create%20table%20%28errno%20150%29" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F05%2Fmysql-error-code-1005-cant-create-table-errno-150%2F&amp;linkname=MySQL%3A%20Error%20code%201005%20Can%E2%80%99t%20create%20table%20%28errno%20150%29" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F05%2Fmysql-error-code-1005-cant-create-table-errno-150%2F&amp;linkname=MySQL%3A%20Error%20code%201005%20Can%E2%80%99t%20create%20table%20%28errno%20150%29" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F05%2Fmysql-error-code-1005-cant-create-table-errno-150%2F&amp;linkname=MySQL%3A%20Error%20code%201005%20Can%E2%80%99t%20create%20table%20%28errno%20150%29" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F05%2Fmysql-error-code-1005-cant-create-table-errno-150%2F&#038;title=MySQL%3A%20Error%20code%201005%20Can%E2%80%99t%20create%20table%20%28errno%20150%29" data-a2a-url="https://www.dbrnd.com/2016/05/mysql-error-code-1005-cant-create-table-errno-150/" data-a2a-title="MySQL: Error code 1005 Can’t create table (errno 150)"></a></p><p>MySQL Error code: 1005 Can’t create table (errno 150).</p>
<p>This error message is a pretty frustrating because it is not properly well-defined error message. </p>
<blockquote><p>I have got this message while creating a table with foreign key constraint. I checked syntax and other things which were also correct.</p></blockquote>
<p>This error looks like an OS file permission issue because it is not able to create a <a href="https://www.dbrnd.com/2016/03/mysql-what-is-the-main-role-of-frm-file/" target="_blank"><strong>.frm file</strong></a>. </p>
<blockquote><p>After some time, I found that my reference column data type is BIGINT and foreign key data type is INT.<br />
Actually, this was a problem of data type mismatching and misleading of the error message.</p></blockquote>
<p><strong>There are some other reasons:</strong></p>
<blockquote><p>The two key fields data type and/or size doesn’t match exactly.<br />
For example, one is INT and another is BIGINT. </p></blockquote>
<blockquote><p>One of the key fields that you are trying to reference does not have an index and/or is not a primary key. If one of the fields in the relationship is not a primary key, you must create an index for that field.</p></blockquote>
<blockquote><p>The foreign key name is a duplicate of an already existing key.</p></blockquote>
<blockquote><p>One or both of your tables is a MyISAM table. In order to use foreign keys, the tables must both be InnoDB. </p></blockquote>
<blockquote><p>You have specified a cascade ON DELETE SET NULL, but the relevant key field is set to NOT NULL. </p></blockquote>
<blockquote><p>Make sure that the Charset and Collate options are the same both at the table level as well as an individual field level for the key columns.</p></blockquote>
<blockquote><p>The name of your foreign key exceeds the max length of 64 chars.</p></blockquote>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>MySQL: How to Enable and Disable Foreign Key Constraint?</title>
		<link>https://www.dbrnd.com/2016/04/mysql-how-to-enable-and-disable-foreign-key-constraint/</link>
					<comments>https://www.dbrnd.com/2016/04/mysql-how-to-enable-and-disable-foreign-key-constraint/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Sat, 23 Apr 2016 20:45:40 +0000</pubDate>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[foreign key]]></category>
		<category><![CDATA[FOREIGN_KEY_CHECKS]]></category>
		<category><![CDATA[MySQL Command]]></category>
		<category><![CDATA[MySQL Database Administrator]]></category>
		<category><![CDATA[MySQL Database Designing]]></category>
		<category><![CDATA[MySQL Database Programming]]></category>
		<category><![CDATA[MySQL Error]]></category>
		<category><![CDATA[MySQL Performance Tunning]]></category>
		<category><![CDATA[MySQL Query]]></category>
		<category><![CDATA[MySQL Tips and Tricks]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=2162</guid>

					<description><![CDATA[In this post, I am sharing a script on how to enable and disable Foreign Key constraint in MySQL. During data migration and testing purpose, Database Developer requires disabling Foreign key constraint. Once you disable the constraint, later you might require enabling again, but during this exercise make sure that all your data changes are [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F04%2Fmysql-how-to-enable-and-disable-foreign-key-constraint%2F&amp;linkname=MySQL%3A%20How%20to%20Enable%20and%20Disable%20Foreign%20Key%20Constraint%3F" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F04%2Fmysql-how-to-enable-and-disable-foreign-key-constraint%2F&amp;linkname=MySQL%3A%20How%20to%20Enable%20and%20Disable%20Foreign%20Key%20Constraint%3F" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F04%2Fmysql-how-to-enable-and-disable-foreign-key-constraint%2F&amp;linkname=MySQL%3A%20How%20to%20Enable%20and%20Disable%20Foreign%20Key%20Constraint%3F" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F04%2Fmysql-how-to-enable-and-disable-foreign-key-constraint%2F&amp;linkname=MySQL%3A%20How%20to%20Enable%20and%20Disable%20Foreign%20Key%20Constraint%3F" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F04%2Fmysql-how-to-enable-and-disable-foreign-key-constraint%2F&amp;linkname=MySQL%3A%20How%20to%20Enable%20and%20Disable%20Foreign%20Key%20Constraint%3F" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F04%2Fmysql-how-to-enable-and-disable-foreign-key-constraint%2F&amp;linkname=MySQL%3A%20How%20to%20Enable%20and%20Disable%20Foreign%20Key%20Constraint%3F" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F04%2Fmysql-how-to-enable-and-disable-foreign-key-constraint%2F&#038;title=MySQL%3A%20How%20to%20Enable%20and%20Disable%20Foreign%20Key%20Constraint%3F" data-a2a-url="https://www.dbrnd.com/2016/04/mysql-how-to-enable-and-disable-foreign-key-constraint/" data-a2a-title="MySQL: How to Enable and Disable Foreign Key Constraint?"></a></p><p>In this post, I am sharing a script on how to enable and disable Foreign Key constraint in MySQL. </p>
<p>During data migration and testing purpose, Database Developer requires disabling Foreign key constraint.</p>
<blockquote><p>Once you disable the constraint, later you might require enabling again, but during this exercise make sure that all your data changes are correct, and as per the constraint rule otherwise, you cannot enable those constraints. It violates data integrity rules. </p></blockquote>
<p>You can perform disable/enable for both global and session levels of MySQL. </p>
<p><strong>At Session level:</strong></p>
<blockquote><p><strong>To Disable:</strong></p>
<pre class="crayon-plain-tag">SET FOREIGN_KEY_CHECKS=0;</pre> </p>
<p><strong>To Enable:</strong></p>
<pre class="crayon-plain-tag">SET FOREIGN_KEY_CHECKS=1;</pre>
</p></blockquote>
<p><strong>At Global level:</strong></p>
<blockquote><p><strong>To Disable:</strong></p><pre class="crayon-plain-tag">SET GLOBAL FOREIGN_KEY_CHECKS=0;</pre><p> </p>
<p><strong>To Enable:</strong></p><pre class="crayon-plain-tag">SET GLOBAL FOREIGN_KEY_CHECKS=1;</pre><p>
</p></blockquote>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2016/04/mysql-how-to-enable-and-disable-foreign-key-constraint/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>MySQL: Script to find Source and Destination of All Foreign Key Constraint</title>
		<link>https://www.dbrnd.com/2016/02/mysql-script-to-find-source-and-destination-of-all-foreign-key-constraint/</link>
					<comments>https://www.dbrnd.com/2016/02/mysql-script-to-find-source-and-destination-of-all-foreign-key-constraint/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Sat, 20 Feb 2016 20:40:10 +0000</pubDate>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[MySQL DBA Script]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[foreign key]]></category>
		<category><![CDATA[INFORMATION_SCHEMA.KEY_COLUMN_USAGE]]></category>
		<category><![CDATA[MySQL Command]]></category>
		<category><![CDATA[MySQL Database Administrator]]></category>
		<category><![CDATA[MySQL Database Designing]]></category>
		<category><![CDATA[MySQL Database Programming]]></category>
		<category><![CDATA[MySQL Error]]></category>
		<category><![CDATA[MySQL Performance Tunning]]></category>
		<category><![CDATA[MySQL Query]]></category>
		<category><![CDATA[MySQL Tips and Tricks]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=1736</guid>

					<description><![CDATA[In this post, I am sharing a script to find the list of Foreign Keys with the source and destination table information of a MySQL Database. Using below script you can easily find all foreign keys of a MySQL Database and its very useful for Database Architect for finding different references of foreign keys. I [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F02%2Fmysql-script-to-find-source-and-destination-of-all-foreign-key-constraint%2F&amp;linkname=MySQL%3A%20Script%20to%20find%20Source%20and%20Destination%20of%20All%20Foreign%20Key%20Constraint" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F02%2Fmysql-script-to-find-source-and-destination-of-all-foreign-key-constraint%2F&amp;linkname=MySQL%3A%20Script%20to%20find%20Source%20and%20Destination%20of%20All%20Foreign%20Key%20Constraint" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F02%2Fmysql-script-to-find-source-and-destination-of-all-foreign-key-constraint%2F&amp;linkname=MySQL%3A%20Script%20to%20find%20Source%20and%20Destination%20of%20All%20Foreign%20Key%20Constraint" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F02%2Fmysql-script-to-find-source-and-destination-of-all-foreign-key-constraint%2F&amp;linkname=MySQL%3A%20Script%20to%20find%20Source%20and%20Destination%20of%20All%20Foreign%20Key%20Constraint" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F02%2Fmysql-script-to-find-source-and-destination-of-all-foreign-key-constraint%2F&amp;linkname=MySQL%3A%20Script%20to%20find%20Source%20and%20Destination%20of%20All%20Foreign%20Key%20Constraint" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F02%2Fmysql-script-to-find-source-and-destination-of-all-foreign-key-constraint%2F&amp;linkname=MySQL%3A%20Script%20to%20find%20Source%20and%20Destination%20of%20All%20Foreign%20Key%20Constraint" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F02%2Fmysql-script-to-find-source-and-destination-of-all-foreign-key-constraint%2F&#038;title=MySQL%3A%20Script%20to%20find%20Source%20and%20Destination%20of%20All%20Foreign%20Key%20Constraint" data-a2a-url="https://www.dbrnd.com/2016/02/mysql-script-to-find-source-and-destination-of-all-foreign-key-constraint/" data-a2a-title="MySQL: Script to find Source and Destination of All Foreign Key Constraint"></a></p><p>In this post, I am sharing a script to find the list of Foreign Keys with the source and destination table information of a MySQL Database. </p>
<blockquote><p>Using below script you can easily find all foreign keys of a MySQL Database and its very useful for Database Architect for finding different references of foreign keys.</p></blockquote>
<p>I am finding all Foreign Key references using INFORMATION_SCHEMA.KEY_COLUMN_USAGE. </p>
<p><strong>Below is a script:</strong></p>
<pre class="crayon-plain-tag">SELECT
  referenced_table_name AS ParentTable
  ,table_name AS ChildTable
  ,constraint_name AS ConstraintName
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
WHERE referenced_table_name IS NOT NULL
ORDER BY referenced_table_name;</pre> </p>
<blockquote class="wp-embedded-content" data-secret="TWCuSL9Nsg"><p><a href="https://www.dbrnd.com/2015/08/find-table-dependency-in-constraint-view-stored-procedure-of-mysql/">Find Table Dependency in MySQL</a></p></blockquote>
<p><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2015/08/find-table-dependency-in-constraint-view-stored-procedure-of-mysql/embed/#?secret=TWCuSL9Nsg" data-secret="TWCuSL9Nsg" width="600" height="338" title="&#8220;Find Table Dependency in MySQL&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<blockquote class="wp-embedded-content" data-secret="pBqkdAxf4j"><p><a href="https://www.dbrnd.com/2015/10/postgresql-script-to-find-source-and-destination-of-all-foreign-key-constraint/">PostgreSQL: Script to find Source and Destination of All Foreign Key Constraint</a></p></blockquote>
<p><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2015/10/postgresql-script-to-find-source-and-destination-of-all-foreign-key-constraint/embed/#?secret=pBqkdAxf4j" data-secret="pBqkdAxf4j" width="600" height="338" title="&#8220;PostgreSQL: Script to find Source and Destination of All Foreign Key Constraint&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<blockquote class="wp-embedded-content" data-secret="pqW0N2BMDU"><p><a href="https://www.dbrnd.com/2015/06/find-foreign-key-reference-source-target-in-sql-server/">How to Find Foreign key References in SQL Server</a></p></blockquote>
<p><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2015/06/find-foreign-key-reference-source-target-in-sql-server/embed/#?secret=pqW0N2BMDU" data-secret="pqW0N2BMDU" width="600" height="338" title="&#8220;How to Find Foreign key References in SQL Server&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2016/02/mysql-script-to-find-source-and-destination-of-all-foreign-key-constraint/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>Enable and Disable Foreign key and Check constraint in SQL Server</title>
		<link>https://www.dbrnd.com/2015/09/enable-disable-foreign-key-and-check-constraint-in-sql-server/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Wed, 16 Sep 2015 18:09:35 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[check]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[foreign key]]></category>
		<category><![CDATA[sp_msforeachtable]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tunning]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=629</guid>

					<description><![CDATA[In this post, I am sharing the script to enable and disable foreign key and check constraint in SQL Server. During data migration and testing purpose, Database Developer requires to disable Foreign key constraint or Check constraint. Once you disable constraint, then later you might need enabling again, but during this exercise make sure that [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F09%2Fenable-disable-foreign-key-and-check-constraint-in-sql-server%2F&amp;linkname=Enable%20and%20Disable%20Foreign%20key%20and%20Check%20constraint%20in%20SQL%20Server" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F09%2Fenable-disable-foreign-key-and-check-constraint-in-sql-server%2F&amp;linkname=Enable%20and%20Disable%20Foreign%20key%20and%20Check%20constraint%20in%20SQL%20Server" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F09%2Fenable-disable-foreign-key-and-check-constraint-in-sql-server%2F&amp;linkname=Enable%20and%20Disable%20Foreign%20key%20and%20Check%20constraint%20in%20SQL%20Server" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F09%2Fenable-disable-foreign-key-and-check-constraint-in-sql-server%2F&amp;linkname=Enable%20and%20Disable%20Foreign%20key%20and%20Check%20constraint%20in%20SQL%20Server" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F09%2Fenable-disable-foreign-key-and-check-constraint-in-sql-server%2F&amp;linkname=Enable%20and%20Disable%20Foreign%20key%20and%20Check%20constraint%20in%20SQL%20Server" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F09%2Fenable-disable-foreign-key-and-check-constraint-in-sql-server%2F&amp;linkname=Enable%20and%20Disable%20Foreign%20key%20and%20Check%20constraint%20in%20SQL%20Server" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F09%2Fenable-disable-foreign-key-and-check-constraint-in-sql-server%2F&#038;title=Enable%20and%20Disable%20Foreign%20key%20and%20Check%20constraint%20in%20SQL%20Server" data-a2a-url="https://www.dbrnd.com/2015/09/enable-disable-foreign-key-and-check-constraint-in-sql-server/" data-a2a-title="Enable and Disable Foreign key and Check constraint in SQL Server"></a></p><p>In this post, I am sharing the script to enable and disable foreign key and check constraint in SQL Server.</p>
<p>During data migration and testing purpose, Database Developer requires to disable Foreign key constraint or Check constraint.</p>
<blockquote><p><em>Once you disable constraint, then later you might need enabling again, but during this exercise make sure that all your data changes are correct, and as per the constraint rule otherwise, you should not enable those constraints.</em></p></blockquote>
<p>You can disable/enable action only on Foreign Key and Check Constraint.<br />
You cannot perform disable/enable on Primary Key and Unique Key.</p>
<p><strong>Disable All Foreign keys and Check Constraints:</strong><br />
<pre class="crayon-plain-tag">EXEC sp_msforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT ALL"</pre>
<p><strong>Enable All Foreign keys and Check Constraints:</strong><br />
<pre class="crayon-plain-tag">EXEC sp_msforeachtable @command1="print '?'", 
@command2="ALTER TABLE ? WITH CHECK CHECK CONSTRAINT ALL"</pre>
<p><strong>Disable all the table constraints:</strong><br />
<pre class="crayon-plain-tag">ALTER TABLE table_name NOCHECK CONSTRAINT ALL</pre>
<p><strong>Enable all the table constraints:</strong><br />
<pre class="crayon-plain-tag">ALTER TABLE table_name CHECK CONSTRAINT ALL</pre>
<p><strong>Disable a single constraint:</strong><br />
<pre class="crayon-plain-tag">ALTER TABLE table_name NOCHECK CONSTRAINT constraint_name</pre>
<p><strong>Enable a single constraint:</strong><br />
<pre class="crayon-plain-tag">ALTER TABLE table_name CHECK CONSTRAINT constraint_name</pre>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>How to Find Foreign key References in SQL Server</title>
		<link>https://www.dbrnd.com/2015/06/find-foreign-key-reference-source-target-in-sql-server/</link>
					<comments>https://www.dbrnd.com/2015/06/find-foreign-key-reference-source-target-in-sql-server/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Sun, 28 Jun 2015 05:58:03 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server DBA Script]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[foreign key]]></category>
		<category><![CDATA[INFORMATION_SCHEMA]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tunning]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=284</guid>

					<description><![CDATA[In this post, I am sharing a script to find the all foreign key sources and destination references of the SQL Server. Whenever we need to check all table references, we can use this script. Below is a script: [crayon-6a9bfc1320144931413091/]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F06%2Ffind-foreign-key-reference-source-target-in-sql-server%2F&amp;linkname=How%20to%20Find%20Foreign%20key%20References%20in%20SQL%20Server" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F06%2Ffind-foreign-key-reference-source-target-in-sql-server%2F&amp;linkname=How%20to%20Find%20Foreign%20key%20References%20in%20SQL%20Server" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F06%2Ffind-foreign-key-reference-source-target-in-sql-server%2F&amp;linkname=How%20to%20Find%20Foreign%20key%20References%20in%20SQL%20Server" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F06%2Ffind-foreign-key-reference-source-target-in-sql-server%2F&amp;linkname=How%20to%20Find%20Foreign%20key%20References%20in%20SQL%20Server" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F06%2Ffind-foreign-key-reference-source-target-in-sql-server%2F&amp;linkname=How%20to%20Find%20Foreign%20key%20References%20in%20SQL%20Server" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F06%2Ffind-foreign-key-reference-source-target-in-sql-server%2F&amp;linkname=How%20to%20Find%20Foreign%20key%20References%20in%20SQL%20Server" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2015%2F06%2Ffind-foreign-key-reference-source-target-in-sql-server%2F&#038;title=How%20to%20Find%20Foreign%20key%20References%20in%20SQL%20Server" data-a2a-url="https://www.dbrnd.com/2015/06/find-foreign-key-reference-source-target-in-sql-server/" data-a2a-title="How to Find Foreign key References in SQL Server"></a></p><p>In this post, I am sharing a script to find the all foreign key sources and destination references of the SQL Server.</p>
<p>Whenever we need to check all table references, we can use this script. </p>
<p><strong>Below is a script:</strong></p>
<pre class="crayon-plain-tag">SELECT 
	ccu.table_name AS SourceTable
	,ccu.constraint_name AS SourceConstraint
	,ccu.column_name AS SourceColumn
	,kcu.table_name AS TargetTable
	,kcu.column_name AS TargetColumn
FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE ccu
	INNER JOIN INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS rc
		ON ccu.CONSTRAINT_NAME = rc.CONSTRAINT_NAME 
	INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE kcu 
		ON kcu.CONSTRAINT_NAME = rc.UNIQUE_CONSTRAINT_NAME  
ORDER BY ccu.table_name</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2015/06/find-foreign-key-reference-source-target-in-sql-server/feed/</wfw:commentRss>
			<slash:comments>7</slash:comments>
		
		
			</item>
	</channel>
</rss>
