<?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>sp_msforeachtable &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/sp_msforeachtable/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>Thu, 14 Sep 2017 11:51:21 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.6</generator>
	<item>
		<title>SQL Server: Use sp_MSforeachtable to apply a T-SQL command to every table of current Database</title>
		<link>https://www.dbrnd.com/2017/09/sql-server-use-sp_msforeachtable-to-apply-a-t-sql-command-to-every-table-of-current-database/</link>
					<comments>https://www.dbrnd.com/2017/09/sql-server-use-sp_msforeachtable-to-apply-a-t-sql-command-to-every-table-of-current-database/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Sat, 02 Sep 2017 16:16:15 +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[index]]></category>
		<category><![CDATA[sp_msforeachtable]]></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[Table]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=6013</guid>

					<description><![CDATA[In this post, I am sharing the use of sp_MSforeachtable stored procedure of SQL Server. This is an undocumented object of SQL Server, but still, you can use this stored procedure. When we require executing same T-SQL command for all the tables, we can use this stored procedure. Many times we need to run drop/truncate [&#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-use-sp_msforeachtable-to-apply-a-t-sql-command-to-every-table-of-current-database%2F&amp;linkname=SQL%20Server%3A%20Use%20sp_MSforeachtable%20to%20apply%20a%20T-SQL%20command%20to%20every%20table%20of%20current%20Database" 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-use-sp_msforeachtable-to-apply-a-t-sql-command-to-every-table-of-current-database%2F&amp;linkname=SQL%20Server%3A%20Use%20sp_MSforeachtable%20to%20apply%20a%20T-SQL%20command%20to%20every%20table%20of%20current%20Database" 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-use-sp_msforeachtable-to-apply-a-t-sql-command-to-every-table-of-current-database%2F&amp;linkname=SQL%20Server%3A%20Use%20sp_MSforeachtable%20to%20apply%20a%20T-SQL%20command%20to%20every%20table%20of%20current%20Database" 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-use-sp_msforeachtable-to-apply-a-t-sql-command-to-every-table-of-current-database%2F&amp;linkname=SQL%20Server%3A%20Use%20sp_MSforeachtable%20to%20apply%20a%20T-SQL%20command%20to%20every%20table%20of%20current%20Database" 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-use-sp_msforeachtable-to-apply-a-t-sql-command-to-every-table-of-current-database%2F&amp;linkname=SQL%20Server%3A%20Use%20sp_MSforeachtable%20to%20apply%20a%20T-SQL%20command%20to%20every%20table%20of%20current%20Database" 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-use-sp_msforeachtable-to-apply-a-t-sql-command-to-every-table-of-current-database%2F&amp;linkname=SQL%20Server%3A%20Use%20sp_MSforeachtable%20to%20apply%20a%20T-SQL%20command%20to%20every%20table%20of%20current%20Database" 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-use-sp_msforeachtable-to-apply-a-t-sql-command-to-every-table-of-current-database%2F&#038;title=SQL%20Server%3A%20Use%20sp_MSforeachtable%20to%20apply%20a%20T-SQL%20command%20to%20every%20table%20of%20current%20Database" data-a2a-url="https://www.dbrnd.com/2017/09/sql-server-use-sp_msforeachtable-to-apply-a-t-sql-command-to-every-table-of-current-database/" data-a2a-title="SQL Server: Use sp_MSforeachtable to apply a T-SQL command to every table of current Database"></a></p><p>In this post, I am sharing the use of sp_MSforeachtable stored procedure of SQL Server.<br />
This is an undocumented object of SQL Server, but still, you can use this stored procedure.</p>
<blockquote><p>When we require executing same T-SQL command for all the tables, we can use this stored procedure.<br />
Many times we need to run drop/truncate command for all tables or REINDEX all tables, at that point instead of the manual script we can use this stored procedure.</p></blockquote>
<p><strong>Sharing few examples:</strong></p>
<p><strong>Truncate all tables of current database:</strong></p>
<pre class="crayon-plain-tag">EXEC sp_MSforeachtable 'TRUNCATE TABLE ?'</pre> </p>
<p><strong>Check the count of all tables:</strong></p>
<pre class="crayon-plain-tag">EXEC sp_MSforeachtable 'TRUNCATE TABLE ?'</pre> </p>
<p><strong>Drop all tables of current database:</strong></p>
<pre class="crayon-plain-tag">EXEC sp_MSforeachtable 'DROP TABLE ?'</pre> </p>
<p><strong>REINDEX all tables of current database:</strong></p>
<pre class="crayon-plain-tag">EXEC sp_MSforeachtable 'DBCC DBREINDEX(''?'')'</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2017/09/sql-server-use-sp_msforeachtable-to-apply-a-t-sql-command-to-every-table-of-current-database/feed/</wfw:commentRss>
			<slash:comments>2</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>
	</channel>
</rss>
