<?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>Temp Table &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/temp-table/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>Sat, 20 Apr 2019 18:30:58 +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: Find Stored Procedures which use Dynamic SQL and Temporary Table</title>
		<link>https://www.dbrnd.com/2019/04/sql-server-find-stored-procedures-which-use-dynamic-sql-and-temporary-table/</link>
					<comments>https://www.dbrnd.com/2019/04/sql-server-find-stored-procedures-which-use-dynamic-sql-and-temporary-table/#respond</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 08 Apr 2019 18:30:46 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server DBA Script]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[Data Security]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[dynamic sql]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[SQL Injection]]></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 Procedure]]></category>
		<category><![CDATA[Temp Table]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=4076</guid>

					<description><![CDATA[Whenever you are searching for SQL query optimization tips or prevent SQL injection tips, you can find few common suggestions like: Please do not use Dynamic SQL in your Stored Procedure. Please try to avoid the use of Temp Tables. I always tell to database developers, please try to avoid the use of Dynamic 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%2F2019%2F04%2Fsql-server-find-stored-procedures-which-use-dynamic-sql-and-temporary-table%2F&amp;linkname=SQL%20Server%3A%20Find%20Stored%20Procedures%20which%20use%20Dynamic%20SQL%20and%20Temporary%20Table" 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%2F04%2Fsql-server-find-stored-procedures-which-use-dynamic-sql-and-temporary-table%2F&amp;linkname=SQL%20Server%3A%20Find%20Stored%20Procedures%20which%20use%20Dynamic%20SQL%20and%20Temporary%20Table" 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%2F04%2Fsql-server-find-stored-procedures-which-use-dynamic-sql-and-temporary-table%2F&amp;linkname=SQL%20Server%3A%20Find%20Stored%20Procedures%20which%20use%20Dynamic%20SQL%20and%20Temporary%20Table" 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%2F04%2Fsql-server-find-stored-procedures-which-use-dynamic-sql-and-temporary-table%2F&amp;linkname=SQL%20Server%3A%20Find%20Stored%20Procedures%20which%20use%20Dynamic%20SQL%20and%20Temporary%20Table" 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%2F04%2Fsql-server-find-stored-procedures-which-use-dynamic-sql-and-temporary-table%2F&amp;linkname=SQL%20Server%3A%20Find%20Stored%20Procedures%20which%20use%20Dynamic%20SQL%20and%20Temporary%20Table" 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%2F04%2Fsql-server-find-stored-procedures-which-use-dynamic-sql-and-temporary-table%2F&amp;linkname=SQL%20Server%3A%20Find%20Stored%20Procedures%20which%20use%20Dynamic%20SQL%20and%20Temporary%20Table" 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%2F04%2Fsql-server-find-stored-procedures-which-use-dynamic-sql-and-temporary-table%2F&#038;title=SQL%20Server%3A%20Find%20Stored%20Procedures%20which%20use%20Dynamic%20SQL%20and%20Temporary%20Table" data-a2a-url="https://www.dbrnd.com/2019/04/sql-server-find-stored-procedures-which-use-dynamic-sql-and-temporary-table/" data-a2a-title="SQL Server: Find Stored Procedures which use Dynamic SQL and Temporary Table"></a></p><p>Whenever you are searching for SQL query optimization tips or prevent SQL injection tips, you can find few common suggestions like: Please do not use Dynamic SQL in your Stored Procedure. Please try to avoid the use of Temp Tables.</p>
<blockquote><p>I always tell to database developers, please try to avoid the use of Dynamic SQL and Temp Table in your Stored Procedures.</p></blockquote>
<blockquote><p>A Temp Table requires additional CPU/IO which degrades the query performance. A Dynamic SQL is not safe against the SQL Injection and It also compiles data every time which requires more Memory. </p></blockquote>
<blockquote><p>Here, I am sharing one of the important scripts which gives you list of SQL Server Stored Procedures, which use the Dynamic SQL and Temp Table.<br />
You can easily get the list of Stored Procedures and can make plans of modifying it.</p></blockquote>
<blockquote><p>Prepared this script using sys.dm_exec_describe_first_result_set and sys.procedures where error number 4 = Dynamic SQL and error number 10 = Temporary Table.</p></blockquote>
<pre class="crayon-plain-tag">SELECT  
	SP_Name
	,error_message
	,error_type_desc 
FROM (SELECT schema_name(schema_id)+'.'+name SP_Name FROM sys.procedures) AS T
CROSS APPLY sys.dm_exec_describe_first_result_set (SP_Name, NULL, 0) 
WHERE error_type IN (4,10)</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2019/04/sql-server-find-stored-procedures-which-use-dynamic-sql-and-temporary-table/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>SQL Server: Optimize the Performance of TempDB</title>
		<link>https://www.dbrnd.com/2018/03/sql-server-optimize-the-performance-of-tempdb-add-multiple-data-files-store-ssd/</link>
					<comments>https://www.dbrnd.com/2018/03/sql-server-optimize-the-performance-of-tempdb-add-multiple-data-files-store-ssd/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Fri, 09 Mar 2018 16:16:11 +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[Multiple data files]]></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[Temp Table]]></category>
		<category><![CDATA[TempDB]]></category>
		<category><![CDATA[TempDB Performance]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=4256</guid>

					<description><![CDATA[<div><img width="679" height="452" src="https://www.dbrnd.com/wp-content/uploads/2017/12/SQL-RAM-Performance-679x452.jpg" class="attachment-post-image size-post-image wp-post-image" alt="SQL RAM Performance" decoding="async" fetchpriority="high" srcset="https://www.dbrnd.com/wp-content/uploads/2017/12/SQL-RAM-Performance-679x452.jpg 679w, https://www.dbrnd.com/wp-content/uploads/2017/12/SQL-RAM-Performance-850x566.jpg 850w, https://www.dbrnd.com/wp-content/uploads/2017/12/SQL-RAM-Performance.jpg 959w" sizes="(max-width: 679px) 100vw, 679px" /></div>The Database Administrator must know something about the best configuration of TempDB. A general advice is, try to avoid the use of TempDB by creating temp tables. But TempDB also stores other information related to query execution, internal sort operation, overflow memory data. You should keep your eye open for TempDB otherwise it degrades the [&#8230;]]]></description>
										<content:encoded><![CDATA[<div><img width="679" height="452" src="https://www.dbrnd.com/wp-content/uploads/2017/12/SQL-RAM-Performance-679x452.jpg" class="attachment-post-image size-post-image wp-post-image" alt="SQL RAM Performance" decoding="async" srcset="https://www.dbrnd.com/wp-content/uploads/2017/12/SQL-RAM-Performance-679x452.jpg 679w, https://www.dbrnd.com/wp-content/uploads/2017/12/SQL-RAM-Performance-850x566.jpg 850w, https://www.dbrnd.com/wp-content/uploads/2017/12/SQL-RAM-Performance.jpg 959w" sizes="(max-width: 679px) 100vw, 679px" /></div><p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F03%2Fsql-server-optimize-the-performance-of-tempdb-add-multiple-data-files-store-ssd%2F&amp;linkname=SQL%20Server%3A%20Optimize%20the%20Performance%20of%20TempDB" 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%2F2018%2F03%2Fsql-server-optimize-the-performance-of-tempdb-add-multiple-data-files-store-ssd%2F&amp;linkname=SQL%20Server%3A%20Optimize%20the%20Performance%20of%20TempDB" 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%2F2018%2F03%2Fsql-server-optimize-the-performance-of-tempdb-add-multiple-data-files-store-ssd%2F&amp;linkname=SQL%20Server%3A%20Optimize%20the%20Performance%20of%20TempDB" 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%2F2018%2F03%2Fsql-server-optimize-the-performance-of-tempdb-add-multiple-data-files-store-ssd%2F&amp;linkname=SQL%20Server%3A%20Optimize%20the%20Performance%20of%20TempDB" 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%2F2018%2F03%2Fsql-server-optimize-the-performance-of-tempdb-add-multiple-data-files-store-ssd%2F&amp;linkname=SQL%20Server%3A%20Optimize%20the%20Performance%20of%20TempDB" 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%2F2018%2F03%2Fsql-server-optimize-the-performance-of-tempdb-add-multiple-data-files-store-ssd%2F&amp;linkname=SQL%20Server%3A%20Optimize%20the%20Performance%20of%20TempDB" 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%2F2018%2F03%2Fsql-server-optimize-the-performance-of-tempdb-add-multiple-data-files-store-ssd%2F&#038;title=SQL%20Server%3A%20Optimize%20the%20Performance%20of%20TempDB" data-a2a-url="https://www.dbrnd.com/2018/03/sql-server-optimize-the-performance-of-tempdb-add-multiple-data-files-store-ssd/" data-a2a-title="SQL Server: Optimize the Performance of TempDB"></a></p><p>The Database Administrator must know something about the best configuration of TempDB.<br />
A general advice is, try to avoid the use of TempDB by creating temp tables.</p>
<p>But TempDB also stores other information related to query execution, internal sort operation, overflow memory data.</p>
<p>You should keep your eye open for TempDB otherwise it degrades the overall performance.</p>
<blockquote class="wp-embedded-content" data-secret="BVUgm0ikvW"><p><a href="https://www.dbrnd.com/2016/02/sql-server-the-tempdb-is-full-shrink-it-or-move-it/">SQL Server: The TempDB is Full, Shrink it or Move it</a></p></blockquote>
<p><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/02/sql-server-the-tempdb-is-full-shrink-it-or-move-it/embed/#?secret=BVUgm0ikvW" data-secret="BVUgm0ikvW" width="600" height="338" title="&#8220;SQL Server: The TempDB is Full, Shrink it or Move it&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<p>Sharing few tips to improve the TempDB performance:</p>
<p><strong>Try to keep TempDB in local drive:</strong></p>
<blockquote><p>You should store TempDB in your local SSD drive instead of the shared network drive. This introduced by SQL Server 2012.</p></blockquote>
<blockquote><p>If you store other databases in shared network drive and TempDB in local drive, It creates a separate path for IO which divides the traffic and improves the performance.</p></blockquote>
<p><strong>Should configure multiple DATA Files:</strong></p>
<blockquote><p>You should create more data files equal to 1/2 or 1/4 the physical CPUs.</p></blockquote>
<blockquote><p>Once you have attached different data files to it, it stripped the files and performed the parallel operations.<br />
Now It has its own PFS, GAM, and SGAM pages, so it spreads the writing process which improves the writing performance.</p></blockquote>
<p><strong>Few other tips:</strong></p>
<ul>
<li>Set the recovery model of tempdb to SIMPLE.</li>
<li>Allow for tempdb files to automatically grow as required.</li>
<li>Set preallocate space for all tempdb files and it prevents tempdb from expanding too frequently.</li>
<li>Make each data file the same size.</li>
</ul>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2018/03/sql-server-optimize-the-performance-of-tempdb-add-multiple-data-files-store-ssd/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>PostgreSQL: Don&#8217;t Create or Drop Temp Table in LOOP, otherwise will get OID does not exist</title>
		<link>https://www.dbrnd.com/2017/08/postgresql-dont-create-or-drop-temp-table-in-loop-otherwise-will-get-oid-does-not-exist/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Tue, 01 Aug 2017 16:16:33 +0000</pubDate>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[plpgsql]]></category>
		<category><![CDATA[Postgres Query]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[PostgreSQL Administrator]]></category>
		<category><![CDATA[PostgreSQL Error]]></category>
		<category><![CDATA[PostgreSQL Monitoring]]></category>
		<category><![CDATA[PostgreSQL Performance Tuning]]></category>
		<category><![CDATA[PostgreSQL Programming]]></category>
		<category><![CDATA[PostgreSQL Tips and Tricks]]></category>
		<category><![CDATA[Temp Table]]></category>
		<category><![CDATA[WHILE LOOP]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=5729</guid>

					<description><![CDATA[Anuraag Veerapaneni &#8211; He is my work coordinator, and he got &#8220;OID does not exist&#8221; error in one of the function execution. Later we found that the problem was in the function code. The temp table was creating and dropping within the WHILE LOOP. Internally, WHILE LOOP also keeps one session, so the OBJECT ID [&#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%2F08%2Fpostgresql-dont-create-or-drop-temp-table-in-loop-otherwise-will-get-oid-does-not-exist%2F&amp;linkname=PostgreSQL%3A%20Don%E2%80%99t%20Create%20or%20Drop%20Temp%20Table%20in%20LOOP%2C%20otherwise%20will%20get%20OID%20does%20not%20exist" 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%2F08%2Fpostgresql-dont-create-or-drop-temp-table-in-loop-otherwise-will-get-oid-does-not-exist%2F&amp;linkname=PostgreSQL%3A%20Don%E2%80%99t%20Create%20or%20Drop%20Temp%20Table%20in%20LOOP%2C%20otherwise%20will%20get%20OID%20does%20not%20exist" 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%2F08%2Fpostgresql-dont-create-or-drop-temp-table-in-loop-otherwise-will-get-oid-does-not-exist%2F&amp;linkname=PostgreSQL%3A%20Don%E2%80%99t%20Create%20or%20Drop%20Temp%20Table%20in%20LOOP%2C%20otherwise%20will%20get%20OID%20does%20not%20exist" 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%2F08%2Fpostgresql-dont-create-or-drop-temp-table-in-loop-otherwise-will-get-oid-does-not-exist%2F&amp;linkname=PostgreSQL%3A%20Don%E2%80%99t%20Create%20or%20Drop%20Temp%20Table%20in%20LOOP%2C%20otherwise%20will%20get%20OID%20does%20not%20exist" 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%2F08%2Fpostgresql-dont-create-or-drop-temp-table-in-loop-otherwise-will-get-oid-does-not-exist%2F&amp;linkname=PostgreSQL%3A%20Don%E2%80%99t%20Create%20or%20Drop%20Temp%20Table%20in%20LOOP%2C%20otherwise%20will%20get%20OID%20does%20not%20exist" 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%2F08%2Fpostgresql-dont-create-or-drop-temp-table-in-loop-otherwise-will-get-oid-does-not-exist%2F&amp;linkname=PostgreSQL%3A%20Don%E2%80%99t%20Create%20or%20Drop%20Temp%20Table%20in%20LOOP%2C%20otherwise%20will%20get%20OID%20does%20not%20exist" 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%2F08%2Fpostgresql-dont-create-or-drop-temp-table-in-loop-otherwise-will-get-oid-does-not-exist%2F&#038;title=PostgreSQL%3A%20Don%E2%80%99t%20Create%20or%20Drop%20Temp%20Table%20in%20LOOP%2C%20otherwise%20will%20get%20OID%20does%20not%20exist" data-a2a-url="https://www.dbrnd.com/2017/08/postgresql-dont-create-or-drop-temp-table-in-loop-otherwise-will-get-oid-does-not-exist/" data-a2a-title="PostgreSQL: Don’t Create or Drop Temp Table in LOOP, otherwise will get OID does not exist"></a></p><p><strong>Anuraag Veerapaneni</strong> &#8211; He is my work coordinator, and he got &#8220;OID does not exist&#8221; error in one of the function execution. </p>
<p>Later we found that the problem was in the function code. The temp table was creating and dropping within the WHILE LOOP. </p>
<blockquote><p>Internally, WHILE LOOP also keeps one session, so the OBJECT ID of dropped temp table still there in the session of WHILE LOOP.<br />
After dropping the temp table, it creates a new temp table in WHILE LOOP with the new object id but dropped temp table object id is still in the session so while selecting a temp table it will search for old Temp table which already dropped.</p></blockquote>
<p>Our advice: please never write code to create or drop temp tables in the WHILE LOOP. </p>
<p><strong>For better understanding, please visit below demonstration:</strong></p>
<p><strong> Create a test function:</strong></p><pre class="crayon-plain-tag">CREATE OR REPLACE FUNCTION fn_check_drop_temp_table()
RETURNS integer
AS
$dbrnd$
 
DECLARE i INT;
j OID;
z OID;
b OID;
a OID;
 
BEGIN   
    i:=0;   
    z:=Coalesce((SELECT relfilenode FROM pg_class
    WHERE relname LIKE '%tmp_drop_test%'),111111);
   
    RAISE NOTICE '%','No table found...'|| z;
   
    DROP TABLE IF EXISTS tmp_a;
    CREATE TABLE tmp_a (col1 int);
       
    WHILE i&lt;=2
    LOOP   
		j:=coalesce((SELECT relfilenode FROM pg_class
		WHERE relname LIKE '%tmp_drop_test%'),1);
		
		RAISE NOTICE '%','1= No data, Other value= OID Data --'|| j;
	   
		DROP TABLE IF EXISTS tmp_drop_test; -- Now drop temp table
		CREATE temp TABLE tmp_drop_test AS SELECT 1 AS int1; -- Create temp table again with same name
	   
		a:=coalesce((SELECT relfilenode FROM pg_class
		WHERE relname LIKE '%tmp_drop_test%'),1);
	   
		RAISE NOTICE '%','After creating temp table - OID of temp table:'|| a; 
		
		INSERT INTO tmp_a
		SELECT * FROM tmp_drop_test;
						
		i:=i+1;   
    END LOOP;   
                RETURN 1;
END;
$dbrnd$
LANGUAGE PLPGSQL;</pre><p> </p>
<p><strong>Now, execute above function:</strong></p>
<pre class="crayon-plain-tag">SELECT *FROM fn_check_drop_temp_table();</pre> </p>
<p><strong>Got error in the result:</strong></p>
<pre class="crayon-plain-tag">NOTICE:  No table found...111111
 
NOTICE:  1= No data, Other value= OID Data --1
 
NOTICE:  After creating temp table - OID of temp table:27102093
 
NOTICE:  1= No data, Other value= OID Data --27102093
 
NOTICE:  After creating temp table - OID of temp table:27102120
 
 
ERROR:  relation with OID 27102093 does not exist
CONTEXT:  SQL statement "INSERT INTO tmp_a SELECT * FROM tmp_drop_test"
PL/pgSQL function "fn_check_drop_temp_table" line 33 at SQL statement</pre> </p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>PostgreSQL: Find a list of active Temp tables with Size and User information</title>
		<link>https://www.dbrnd.com/2017/06/postgresql-find-a-list-of-active-temp-tables-with-size-and-user-information-idle-connection/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Tue, 13 Jun 2017 16:16:32 +0000</pubDate>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[PostgreSQL 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[plpgsql]]></category>
		<category><![CDATA[Postgres Query]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[PostgreSQL Administrator]]></category>
		<category><![CDATA[PostgreSQL Error]]></category>
		<category><![CDATA[PostgreSQL Monitoring]]></category>
		<category><![CDATA[PostgreSQL Performance Tuning]]></category>
		<category><![CDATA[PostgreSQL Programming]]></category>
		<category><![CDATA[PostgreSQL Tips and Tricks]]></category>
		<category><![CDATA[Temp Table]]></category>
		<category><![CDATA[Temp Table Size]]></category>
		<category><![CDATA[Temp Tables]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=5404</guid>

					<description><![CDATA[In this post, I am sharing a script to find a list of Temp tables with their size and user information in PostgreSQL. We all aware of the temp tables and many times developers are creating temp table for their ad-hoc testing purpose. But unfortunately sometimes, they forget to drop unused temp tables, and temp [&#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%2F06%2Fpostgresql-find-a-list-of-active-temp-tables-with-size-and-user-information-idle-connection%2F&amp;linkname=PostgreSQL%3A%20Find%20a%20list%20of%20active%20Temp%20tables%20with%20Size%20and%20User%20information" 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%2F06%2Fpostgresql-find-a-list-of-active-temp-tables-with-size-and-user-information-idle-connection%2F&amp;linkname=PostgreSQL%3A%20Find%20a%20list%20of%20active%20Temp%20tables%20with%20Size%20and%20User%20information" 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%2F06%2Fpostgresql-find-a-list-of-active-temp-tables-with-size-and-user-information-idle-connection%2F&amp;linkname=PostgreSQL%3A%20Find%20a%20list%20of%20active%20Temp%20tables%20with%20Size%20and%20User%20information" 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%2F06%2Fpostgresql-find-a-list-of-active-temp-tables-with-size-and-user-information-idle-connection%2F&amp;linkname=PostgreSQL%3A%20Find%20a%20list%20of%20active%20Temp%20tables%20with%20Size%20and%20User%20information" 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%2F06%2Fpostgresql-find-a-list-of-active-temp-tables-with-size-and-user-information-idle-connection%2F&amp;linkname=PostgreSQL%3A%20Find%20a%20list%20of%20active%20Temp%20tables%20with%20Size%20and%20User%20information" 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%2F06%2Fpostgresql-find-a-list-of-active-temp-tables-with-size-and-user-information-idle-connection%2F&amp;linkname=PostgreSQL%3A%20Find%20a%20list%20of%20active%20Temp%20tables%20with%20Size%20and%20User%20information" 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%2F06%2Fpostgresql-find-a-list-of-active-temp-tables-with-size-and-user-information-idle-connection%2F&#038;title=PostgreSQL%3A%20Find%20a%20list%20of%20active%20Temp%20tables%20with%20Size%20and%20User%20information" data-a2a-url="https://www.dbrnd.com/2017/06/postgresql-find-a-list-of-active-temp-tables-with-size-and-user-information-idle-connection/" data-a2a-title="PostgreSQL: Find a list of active Temp tables with Size and User information"></a></p><p>In this post, I am sharing a script to find a list of Temp tables with their size and user information in PostgreSQL. </p>
<blockquote><p>We all aware of the temp tables and many times developers are creating temp table for their ad-hoc testing purpose.<br />
But unfortunately sometimes, they forget to drop unused temp tables, and temp tables keep active in those idle connections. It also requires unnecessary utilization of disk space.</p></blockquote>
<p>So now, DBAs are responsible for identifying unused temp tables and then inform to developers so that they can drop their unused temp tables.</p>
<pre class="crayon-plain-tag">SELECT
	n.nspname as SchemaName
	,c.relname as RelationName
	,CASE c.relkind
	WHEN 'r' THEN 'table'
	WHEN 'v' THEN 'view'
	WHEN 'i' THEN 'index'
	WHEN 'S' THEN 'sequence'
	WHEN 's' THEN 'special'
	END as RelationType
	,pg_catalog.pg_get_userbyid(c.relowner) as RelationOwner               
	,pg_size_pretty(pg_relation_size(n.nspname ||'.'|| c.relname)) as RelationSize
FROM pg_catalog.pg_class c
LEFT JOIN pg_catalog.pg_namespace n               
                ON n.oid = c.relnamespace
WHERE  c.relkind IN ('r','s') 
AND  (n.nspname !~ '^pg_toast' and nspname like 'pg_temp%')
ORDER BY pg_relation_size(n.nspname ||'.'|| c.relname) DESC</pre> </p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>SQL Server: Create index on large Temp Tables</title>
		<link>https://www.dbrnd.com/2017/02/sql-server-create-index-on-large-temp-tables-clustered-non-clustered-index/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Sun, 26 Feb 2017 16:16:02 +0000</pubDate>
				<category><![CDATA[SQL Server Interview]]></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[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 Tuning]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[Temp db Performance]]></category>
		<category><![CDATA[Temp Table]]></category>
		<category><![CDATA[TempDB]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=4198</guid>

					<description><![CDATA[I have given one assignment to a database developer team for preparing general database development practices. I have found one point in that document: &#8220;Do not create Indexes on Temp Tables&#8221;. The use of Temp Tables is very common in SQL Server. Most of the SQL database developers are storing their data into temp tables. [&#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-create-index-on-large-temp-tables-clustered-non-clustered-index%2F&amp;linkname=SQL%20Server%3A%20Create%20index%20on%20large%20Temp%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%2F2017%2F02%2Fsql-server-create-index-on-large-temp-tables-clustered-non-clustered-index%2F&amp;linkname=SQL%20Server%3A%20Create%20index%20on%20large%20Temp%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%2F2017%2F02%2Fsql-server-create-index-on-large-temp-tables-clustered-non-clustered-index%2F&amp;linkname=SQL%20Server%3A%20Create%20index%20on%20large%20Temp%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%2F2017%2F02%2Fsql-server-create-index-on-large-temp-tables-clustered-non-clustered-index%2F&amp;linkname=SQL%20Server%3A%20Create%20index%20on%20large%20Temp%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%2F2017%2F02%2Fsql-server-create-index-on-large-temp-tables-clustered-non-clustered-index%2F&amp;linkname=SQL%20Server%3A%20Create%20index%20on%20large%20Temp%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%2F2017%2F02%2Fsql-server-create-index-on-large-temp-tables-clustered-non-clustered-index%2F&amp;linkname=SQL%20Server%3A%20Create%20index%20on%20large%20Temp%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%2F2017%2F02%2Fsql-server-create-index-on-large-temp-tables-clustered-non-clustered-index%2F&#038;title=SQL%20Server%3A%20Create%20index%20on%20large%20Temp%20Tables" data-a2a-url="https://www.dbrnd.com/2017/02/sql-server-create-index-on-large-temp-tables-clustered-non-clustered-index/" data-a2a-title="SQL Server: Create index on large Temp Tables"></a></p><p><em>I have given one assignment to a database developer team for preparing general database development practices.<br />
I have found one point in that document: &#8220;Do not create Indexes on Temp Tables&#8221;.</em></p>
<p>The use of Temp Tables is very common in SQL Server. Most of the SQL database developers are storing their data into temp tables.<br />
Let me, explore something about, the best practices of Temp Tables. </p>
<blockquote><p>In general advice, we should avoid the use of temp tables because it requires more CPU/IO while accessing the TempDB.<br />
When you are storing data into temp tables, it stores in TempDB files means the physical disk operation is involved.</p></blockquote>
<blockquote><p>Like any other regular table, temp table also requires disk space to store temporary data and other resources for manipulation.</p></blockquote>
<blockquote><p>I have seen that many developers are saving a significant number of records in Temp Tables and they are not thinking even for Indexing on Temp Tables.</p></blockquote>
<blockquote><p>If you don&#8217;t know, please note: You can create a Clustered and Non-Clustered Indexes on Temp Tables which improves your query performance.</p></blockquote>
<blockquote><p>Again, more indexes will create more problems because it needs space and manipulation.<br />
First, you should analyze the volume of data, execution plan and accordingly you should apply indexes on Temp tables.</p></blockquote>
<blockquote><p>Personally, I have checked the performance of Temp Tables with Clustered Index, which is much better than Temp Table without an Indexes. </p></blockquote>
<p><em>I am rejecting all comments and points which say that &#8221; we should not apply Indexes on Temp Tables. &#8220;</em></p>
<blockquote class="wp-embedded-content" data-secret="BbyB9dqjyi"><p><a href="https://www.dbrnd.com/2016/02/sql-server-difference-between-temporary-table-and-table-variable/">SQL Server: Difference between Temporary Table and Table Variable</a></p></blockquote>
<p><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/02/sql-server-difference-between-temporary-table-and-table-variable/embed/#?secret=BbyB9dqjyi" data-secret="BbyB9dqjyi" width="600" height="338" title="&#8220;SQL Server: Difference between Temporary Table and Table Variable&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>MySQL 5.7: Script to find list of Active InnoDB Temp Tables using INNODB_TEMP_TABLE_INFO</title>
		<link>https://www.dbrnd.com/2016/10/mysql-5-7-script-to-find-list-of-active-innodb-temp-tables-using-innodb_temp_table_info/</link>
					<comments>https://www.dbrnd.com/2016/10/mysql-5-7-script-to-find-list-of-active-innodb-temp-tables-using-innodb_temp_table_info/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Tue, 18 Oct 2016 16:16:03 +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[find active temp table]]></category>
		<category><![CDATA[INNODB_TEMP_TABLE_INFO]]></category>
		<category><![CDATA[MySQL 5.7]]></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>
		<category><![CDATA[Temp Table]]></category>
		<category><![CDATA[temporary table]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=3800</guid>

					<description><![CDATA[MySQL 5.7 introduced INNODB_TEMP_TABLE_INFO table added into INFORMATION_SCHEMA. Using INNODB_TEMP_TABLE_INFO, you can get A list of all active Temp Table of MySQL InnoDB Instance. You can get the information of all active user created and system created Temp Tables. The Database Administrator can use this script for monitoring total Temp Table in MySQL Server. Unnecessarily, [&#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%2F10%2Fmysql-5-7-script-to-find-list-of-active-innodb-temp-tables-using-innodb_temp_table_info%2F&amp;linkname=MySQL%205.7%3A%20Script%20to%20find%20list%20of%20Active%20InnoDB%20Temp%20Tables%20using%20INNODB_TEMP_TABLE_INFO" 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%2F10%2Fmysql-5-7-script-to-find-list-of-active-innodb-temp-tables-using-innodb_temp_table_info%2F&amp;linkname=MySQL%205.7%3A%20Script%20to%20find%20list%20of%20Active%20InnoDB%20Temp%20Tables%20using%20INNODB_TEMP_TABLE_INFO" 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%2F10%2Fmysql-5-7-script-to-find-list-of-active-innodb-temp-tables-using-innodb_temp_table_info%2F&amp;linkname=MySQL%205.7%3A%20Script%20to%20find%20list%20of%20Active%20InnoDB%20Temp%20Tables%20using%20INNODB_TEMP_TABLE_INFO" 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%2F10%2Fmysql-5-7-script-to-find-list-of-active-innodb-temp-tables-using-innodb_temp_table_info%2F&amp;linkname=MySQL%205.7%3A%20Script%20to%20find%20list%20of%20Active%20InnoDB%20Temp%20Tables%20using%20INNODB_TEMP_TABLE_INFO" 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%2F10%2Fmysql-5-7-script-to-find-list-of-active-innodb-temp-tables-using-innodb_temp_table_info%2F&amp;linkname=MySQL%205.7%3A%20Script%20to%20find%20list%20of%20Active%20InnoDB%20Temp%20Tables%20using%20INNODB_TEMP_TABLE_INFO" 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%2F10%2Fmysql-5-7-script-to-find-list-of-active-innodb-temp-tables-using-innodb_temp_table_info%2F&amp;linkname=MySQL%205.7%3A%20Script%20to%20find%20list%20of%20Active%20InnoDB%20Temp%20Tables%20using%20INNODB_TEMP_TABLE_INFO" 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%2F10%2Fmysql-5-7-script-to-find-list-of-active-innodb-temp-tables-using-innodb_temp_table_info%2F&#038;title=MySQL%205.7%3A%20Script%20to%20find%20list%20of%20Active%20InnoDB%20Temp%20Tables%20using%20INNODB_TEMP_TABLE_INFO" data-a2a-url="https://www.dbrnd.com/2016/10/mysql-5-7-script-to-find-list-of-active-innodb-temp-tables-using-innodb_temp_table_info/" data-a2a-title="MySQL 5.7: Script to find list of Active InnoDB Temp Tables using INNODB_TEMP_TABLE_INFO"></a></p><p>MySQL 5.7 introduced INNODB_TEMP_TABLE_INFO table added into INFORMATION_SCHEMA. </p>
<blockquote><p>Using INNODB_TEMP_TABLE_INFO, you can get A list of all active Temp Table of MySQL InnoDB Instance.<br />
You can get the information of all active user created and system created Temp Tables.
</p></blockquote>
<blockquote><p>The Database Administrator can use this script for monitoring total Temp Table in MySQL Server.<br />
Unnecessarily, we should not create a TEMP Table because It requires temporary disk + memory storage and degrade the overall performance of MySQL Server. </p></blockquote>
<p>Once you get the list of tables using INNODB_TEMP_TABLE_INFO, you can get system generated Temp Table Name.</p>
<p><strong>Check existance of INNODB_TEMP_TABLE_INFO:</strong></p>
<pre class="crayon-plain-tag">SHOW TABLES FROM INFORMATION_SCHEMA LIKE 'INNODB_TEMP%';</pre> </p>
<p><strong>Create two sample Temporary Table:</strong></p>
<pre class="crayon-plain-tag">CREATE TEMPORARY TABLE ABC (ID INT, Name VARCHAR(50));
CREATE TEMPORARY TABLE XYZ (ID INT, Name VARCHAR(50));</pre> </p>
<p><strong>Get the information of Temp Table:</strong></p>
<pre class="crayon-plain-tag">SELECT * FROM INFORMATION_SCHEMA.INNODB_TEMP_TABLE_INFO

*************************** 1. row ***************************
            TABLE_ID: 93
                NAME: #sqlcec_9_bec
              N_COLS: 5
               SPACE: 76
PER_TABLE_TABLESPACE: FALSE
       IS_COMPRESSED: FALSE
*************************** 2. row ***************************
            TABLE_ID: 92
                NAME: #sqlcec_9_beb
              N_COLS: 5
               SPACE: 76
PER_TABLE_TABLESPACE: FALSE
       IS_COMPRESSED: FALSE
2 rows in set (0.01 sec)</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2016/10/mysql-5-7-script-to-find-list-of-active-innodb-temp-tables-using-innodb_temp_table_info/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>SQL Server: Database Developer (T-SQL) Interview Questions and Answers (Day-5)</title>
		<link>https://www.dbrnd.com/2016/06/sql-server-database-developer-t-sql-interview-questions-and-answers-database-join-temporary-table-table-variable-cardinality-day-5/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Thu, 16 Jun 2016 18:12:49 +0000</pubDate>
				<category><![CDATA[SQL Server Interview]]></category>
		<category><![CDATA[answers]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[cardinality]]></category>
		<category><![CDATA[cte]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[Database Developer]]></category>
		<category><![CDATA[database joins]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[interview]]></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[Table Variable]]></category>
		<category><![CDATA[Temp Table]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=3045</guid>

					<description><![CDATA[What is an Inner join? The join that displays only the rows that have a match in both the joined tables is known as inner join. What is an Equi join? Equi join is a special type of join in which we use only equality operator. Hence, when you make a query for join using [&#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-database-join-temporary-table-table-variable-cardinality-day-5%2F&amp;linkname=SQL%20Server%3A%20Database%20Developer%20%28T-SQL%29%20Interview%20Questions%20and%20Answers%20%28Day-5%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-database-join-temporary-table-table-variable-cardinality-day-5%2F&amp;linkname=SQL%20Server%3A%20Database%20Developer%20%28T-SQL%29%20Interview%20Questions%20and%20Answers%20%28Day-5%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-database-join-temporary-table-table-variable-cardinality-day-5%2F&amp;linkname=SQL%20Server%3A%20Database%20Developer%20%28T-SQL%29%20Interview%20Questions%20and%20Answers%20%28Day-5%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-database-join-temporary-table-table-variable-cardinality-day-5%2F&amp;linkname=SQL%20Server%3A%20Database%20Developer%20%28T-SQL%29%20Interview%20Questions%20and%20Answers%20%28Day-5%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-database-join-temporary-table-table-variable-cardinality-day-5%2F&amp;linkname=SQL%20Server%3A%20Database%20Developer%20%28T-SQL%29%20Interview%20Questions%20and%20Answers%20%28Day-5%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-database-join-temporary-table-table-variable-cardinality-day-5%2F&amp;linkname=SQL%20Server%3A%20Database%20Developer%20%28T-SQL%29%20Interview%20Questions%20and%20Answers%20%28Day-5%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-database-join-temporary-table-table-variable-cardinality-day-5%2F&#038;title=SQL%20Server%3A%20Database%20Developer%20%28T-SQL%29%20Interview%20Questions%20and%20Answers%20%28Day-5%29" data-a2a-url="https://www.dbrnd.com/2016/06/sql-server-database-developer-t-sql-interview-questions-and-answers-database-join-temporary-table-table-variable-cardinality-day-5/" data-a2a-title="SQL Server: Database Developer (T-SQL) Interview Questions and Answers (Day-5)"></a></p><p><strong>What is an Inner join?</strong></p>
<blockquote><p>The join that displays only the rows that have a match in both the joined tables is known as inner join.</p></blockquote>
<p><strong>What is an Equi join?</strong></p>
<blockquote><p>Equi join is a special type of join in which we use only equality operator. Hence, when you make a query for join using equality operator, then that join query comes under Equi join.</p>
<p>Equi join has only (=) operator in join condition.</p>
<p>Equi join can be inner join, left outer join, right outer join.</p></blockquote>
<p><strong>What is a Left Outer join?</strong></p>
<blockquote><p>Left join displays all the rows from the first table and matched rows from second table like that.</p></blockquote>
<p><strong>What is a Right outer join?</strong></p>
<blockquote><p>Right outer join displays all the rows of second table and matched rows from first table.</p></blockquote>
<p><strong>What is a Full outer join?</strong></p>
<blockquote><p>Full outer join returns all the rows from both tables whether it has been matched or not.</p></blockquote>
<p><strong>What is a Cross Join?</strong></p>
<blockquote><p>A cross join that produces Cartesian product of the tables that are involved in the join. The size of a Cartesian product is the number of the rows in the first table multiplied by the number of rows in the second table.</p></blockquote>
<p><strong>What is a Self join?</strong></p>
<blockquote><p>Joining the table itself called self join. Self join is used to retrieve the records having some relation or similarity with other records in the same table. Here, we need to use aliases for the same table to set a self join between single table and retrieve records satisfying the condition in where clause</p></blockquote>
<p><strong>What is the difference between cross join and Full outer join?</strong></p>
<p><strong>Cross Join:</strong></p>
<ul>
<li>It produces the Cartesian product.</li>
<li>Results in Cartesian product of two tables.</li>
<li>Results in pairs of rows.</li>
<li>No join conditions are specified.</li>
</ul>
<p><strong>Full Outer Join:</strong></p>
<ul>
<li>It includes all the rows from both the tables.</li>
<li>Assigns NULL for unmatched fields.</li>
<li>Results in every row from both of the tables , at least once.</li>
<li>A combination of both left and right outer joins.</li>
</ul>
<p><strong>What is the difference between Temp table and Common table Expression (CTE)?</strong></p>
<blockquote class="wp-embedded-content" data-secret="7sE1TwDePR"><p><a href="https://www.dbrnd.com/2016/02/sql-server-difference-between-temp-table-and-common-table-expression-cte/">SQL Server: Difference between Temp Table and Common Table Expression (CTE)</a></p></blockquote>
<p><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/02/sql-server-difference-between-temp-table-and-common-table-expression-cte/embed/#?secret=7sE1TwDePR" data-secret="7sE1TwDePR" width="600" height="338" title="&#8220;SQL Server: Difference between Temp Table and Common Table Expression (CTE)&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<p><strong>What is the difference between Temp table and Table Variable?</strong></p>
<blockquote class="wp-embedded-content" data-secret="5yNwchT1WL"><p><a href="https://www.dbrnd.com/2016/02/sql-server-difference-between-temporary-table-and-table-variable/">SQL Server: Difference between Temporary Table and Table Variable</a></p></blockquote>
<p><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/02/sql-server-difference-between-temporary-table-and-table-variable/embed/#?secret=5yNwchT1WL" data-secret="5yNwchT1WL" width="600" height="338" title="&#8220;SQL Server: Difference between Temporary Table and Table Variable&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<p><strong>What is the difference between Local and Global Temp Table?</strong></p>
<p>There are two types of temporary tables: local and global. Local temporary tables are visible only to their creators during the same connection to an instance of SQL Server as when the tables were first created or referenced. Local temporary tables are deleted after the user disconnects from the instance of SQL Server. Global temporary tables are visible to any user and any connection after they are created, and are deleted when all users that are referencing the table disconnect from the instance of SQL Server.</p>
<p><strong>How to execute Large SQL Script File by using SQLCmd?</strong></p>
<blockquote><p>sqlcmd -S [servername] -d [databasename] -i [scriptfilename]</blockquote>
<p><strong>What is ASCII method?</strong></p>
<blockquote><p>ASCII will return the ascii value of the character expression.</p></blockquote>
<p><strong>Would do you please write syntax of table variable?</strong></p>
<blockquote><p>DECLARE @TableVariabl Table (ID INT, Name VARCHAR(150))</p></blockquote>
<p><strong>How do we unlock particular user in SQL Server?</strong></p>
<blockquote><p>First login with system admin user and execute below ALTER command.</p>
<p>ALTER LOGIN login_name WITH password=&#8217;password&#8217; unlock;</p></blockquote>
<p><strong>What is the performance difference between EXISTS and IN?</strong></p>
<blockquote><p>EXISTS is efficient as if any row returned and it stops the further search.</p>
<p>IN is looking for a specific match which takes longer.</p>
<p>However, they may not always replace each other and we should use as per our system requirements.</p></blockquote>
<p><strong>Is SQL Case sensitive?</strong></p>
<blockquote><p>No: SQL is not case sensitive.</p></blockquote>
<p><strong>What are the different types of cardinality in SQL?</strong></p>
<blockquote><p><strong>High-cardinality:</strong> refers to columns with values that are very uncommon or unique. High-cardinality column values are typically identification numbers, email addresses, or user names. An example of a data table column with high-cardinality would be a USERS table with a column named USER_ID. This column would contain unique values of 1-n. Each time a new user is created in the USERS table, a new number would be created in the USER_ID column to identify them uniquely. Since the values held in the USER_ID column are unique, this column&#8217;s cardinality type would be referred to as high-cardinality.</p>
<p><strong>Normal-cardinality:</strong> refers to columns with values that are somewhat uncommon. Normal-cardinality column values are typically names, street addresses, or vehicle types. An example of a data table column with normal-cardinality would be a CUSTOMER table with a column named LAST_NAME, containing the last names of customers. While some people have common last names, such as Smith, others have uncommon last names. Therefore, an examination of all of the values held in the LAST_NAME column would show &#8220;clumps&#8221; of names in some places (e.g. a lot of Smith&#8217;s) surrounded on both sides by a long series of unique values. Since there is a variety of possible values held in this column, its cardinality type would be referred to as normal-cardinality.</p>
<p><strong>Low-cardinality:</strong> refers to columns with few unique values. Low-cardinality column values are typically status flags, Boolean values, or major classifications such as gender. An example of a data table column with low-cardinality would be a CUSTOMER table with a column named NEW_CUSTOMER. This column would contain only two distinct values: Y or N, denoting whether the customer was new or not. Since there are only two possible values held in this column, its cardinality type would be referred to as low-cardinality.</p></blockquote>
<p><strong>How to find any Text, Column, Comment, Object Name in SQL Server Objects?</strong></p>
<blockquote class="wp-embedded-content" data-secret="LHHgugG5ak"><p><a href="https://www.dbrnd.com/2015/06/how-to-find-any-text-column-comment-object-name-in-sql-server-objects/">How to find any Text, Column, Comment, Object Name in SQL Server Objects</a></p></blockquote>
<p><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2015/06/how-to-find-any-text-column-comment-object-name-in-sql-server-objects/embed/#?secret=LHHgugG5ak" data-secret="LHHgugG5ak" width="600" height="338" title="&#8220;How to find any Text, Column, Comment, Object Name in SQL Server Objects&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<p><strong>How to Find Missing Number and ID in the SQL Server?</strong></p>
<blockquote class="wp-embedded-content" data-secret="nb1IILJnvE"><p><a href="https://www.dbrnd.com/2015/06/query-to-find-missing-number-id-sql-server/">Query to Find Missing Number and ID 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/query-to-find-missing-number-id-sql-server/embed/#?secret=nb1IILJnvE" data-secret="nb1IILJnvE" width="600" height="338" title="&#8220;Query to Find Missing Number and ID in SQL Server&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>SQL Server: Difference between Temp Table and Common Table Expression (CTE)</title>
		<link>https://www.dbrnd.com/2016/02/sql-server-difference-between-temp-table-and-common-table-expression-cte/</link>
					<comments>https://www.dbrnd.com/2016/02/sql-server-difference-between-temp-table-and-common-table-expression-cte/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Thu, 18 Feb 2016 19:21:44 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[Common Table Expression]]></category>
		<category><![CDATA[cte]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></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[Temp Table]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=1621</guid>

					<description><![CDATA[In this post, I am sharing the important difference between Temp Table and Common Table Expression (CTE) of the SQL Server. I recently wrote an article on the difference between Temp Table and Table Variable of the SQL Server. SQL Server: Difference between Temporary Table and Table Variable The theory and practice of Temp Table, [&#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%2Fsql-server-difference-between-temp-table-and-common-table-expression-cte%2F&amp;linkname=SQL%20Server%3A%20Difference%20between%20Temp%20Table%20and%20Common%20Table%20Expression%20%28CTE%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%2F02%2Fsql-server-difference-between-temp-table-and-common-table-expression-cte%2F&amp;linkname=SQL%20Server%3A%20Difference%20between%20Temp%20Table%20and%20Common%20Table%20Expression%20%28CTE%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%2F02%2Fsql-server-difference-between-temp-table-and-common-table-expression-cte%2F&amp;linkname=SQL%20Server%3A%20Difference%20between%20Temp%20Table%20and%20Common%20Table%20Expression%20%28CTE%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%2F02%2Fsql-server-difference-between-temp-table-and-common-table-expression-cte%2F&amp;linkname=SQL%20Server%3A%20Difference%20between%20Temp%20Table%20and%20Common%20Table%20Expression%20%28CTE%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%2F02%2Fsql-server-difference-between-temp-table-and-common-table-expression-cte%2F&amp;linkname=SQL%20Server%3A%20Difference%20between%20Temp%20Table%20and%20Common%20Table%20Expression%20%28CTE%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%2F02%2Fsql-server-difference-between-temp-table-and-common-table-expression-cte%2F&amp;linkname=SQL%20Server%3A%20Difference%20between%20Temp%20Table%20and%20Common%20Table%20Expression%20%28CTE%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%2F02%2Fsql-server-difference-between-temp-table-and-common-table-expression-cte%2F&#038;title=SQL%20Server%3A%20Difference%20between%20Temp%20Table%20and%20Common%20Table%20Expression%20%28CTE%29" data-a2a-url="https://www.dbrnd.com/2016/02/sql-server-difference-between-temp-table-and-common-table-expression-cte/" data-a2a-title="SQL Server: Difference between Temp Table and Common Table Expression (CTE)"></a></p><p>In this post, I am sharing the important difference between Temp Table and Common Table Expression (CTE) of the SQL Server.<br />
<code>I recently wrote an article on the difference between Temp Table and Table Variable of the SQL Server. </code></p>
<blockquote class="wp-embedded-content" data-secret="hLRo3QNO6Y"><p><a href="https://www.dbrnd.com/2016/02/sql-server-difference-between-temporary-table-and-table-variable/">SQL Server: Difference between Temporary Table and Table Variable</a></p></blockquote>
<p><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/02/sql-server-difference-between-temporary-table-and-table-variable/embed/#?secret=hLRo3QNO6Y" data-secret="hLRo3QNO6Y" width="600" height="338" title="&#8220;SQL Server: Difference between Temporary Table and Table Variable&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<p>The theory and practice of Temp Table, Table Variable and CTE is one of my favourite topics of the SQL Server. </p>
<blockquote><p>A CTE is used for a temporary result set that is defined within the execution scope of the query.<br />
A Temp Table is also used for a temporary result set, but it can be defined for limited execution scope or can be used to define for global execution scope as a Global Temp Table. </p></blockquote>
<blockquote><p>A CTE is substituted for a view when the general use of a view is not required, and you do not have to store the definition of metadata. </p></blockquote>
<blockquote><p>CTE always uses memory and Temp Table stored in the TempDB. </p></blockquote>
<blockquote><p>The Scope of CTE is only for the query and can be referenced multiple times in other CTEs.<br />
The child objects also access the Temp Table, and it persists until the end of the sessions.
</p></blockquote>
<blockquote><p>We can not use NOLOCK and other isolation levels with CTE and with the Temp Table, we can apply it explicitly. </p></blockquote>
<blockquote><p>If we require to CTE for another batch query, it requires recreation of it.<br />
The Temp Table can be used for all batches of a session. </p></blockquote>
<blockquote><p>A CTE doesn&#8217;t maintain any statistics and any metadata information, Temp table is maintaining a require statistics.</p></blockquote>
<blockquote><p>A CTE is a never part of the transaction and locking and its treated as system transaction.<br />
The temp table operations are a part of user transactions. </p></blockquote>
<blockquote><p>If we have a large dataset, we should use Temp Table and with the small dataset, we can use CTE very effectively. </p></blockquote>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2016/02/sql-server-difference-between-temp-table-and-common-table-expression-cte/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>SQL Server: Difference between Temporary Table and Table Variable</title>
		<link>https://www.dbrnd.com/2016/02/sql-server-difference-between-temporary-table-and-table-variable/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Fri, 12 Feb 2016 18:54:45 +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[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[Table Variable]]></category>
		<category><![CDATA[Temp Table]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=1597</guid>

					<description><![CDATA[Sharing one of the timeworn topics and we can also find an N number of good articles on this. I also like this topic very much so I would like to write a small note on this. First, Very important point: Temp table is stored in TempDB and Table variable is stored in Memory. 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%2F2016%2F02%2Fsql-server-difference-between-temporary-table-and-table-variable%2F&amp;linkname=SQL%20Server%3A%20Difference%20between%20Temporary%20Table%20and%20Table%20Variable" 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%2Fsql-server-difference-between-temporary-table-and-table-variable%2F&amp;linkname=SQL%20Server%3A%20Difference%20between%20Temporary%20Table%20and%20Table%20Variable" 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%2Fsql-server-difference-between-temporary-table-and-table-variable%2F&amp;linkname=SQL%20Server%3A%20Difference%20between%20Temporary%20Table%20and%20Table%20Variable" 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%2Fsql-server-difference-between-temporary-table-and-table-variable%2F&amp;linkname=SQL%20Server%3A%20Difference%20between%20Temporary%20Table%20and%20Table%20Variable" 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%2Fsql-server-difference-between-temporary-table-and-table-variable%2F&amp;linkname=SQL%20Server%3A%20Difference%20between%20Temporary%20Table%20and%20Table%20Variable" 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%2Fsql-server-difference-between-temporary-table-and-table-variable%2F&amp;linkname=SQL%20Server%3A%20Difference%20between%20Temporary%20Table%20and%20Table%20Variable" 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%2Fsql-server-difference-between-temporary-table-and-table-variable%2F&#038;title=SQL%20Server%3A%20Difference%20between%20Temporary%20Table%20and%20Table%20Variable" data-a2a-url="https://www.dbrnd.com/2016/02/sql-server-difference-between-temporary-table-and-table-variable/" data-a2a-title="SQL Server: Difference between Temporary Table and Table Variable"></a></p><p>Sharing one of the timeworn topics and we can also find an N number of good articles on this. </p>
<p>I also like this topic very much so I would like to write a small note on this.</p>
<p><strong>First, Very important point:</strong></p>
<blockquote><p>Temp table is stored in TempDB and Table variable is stored in Memory.<br />
<strong>The above statement is 100% wrong.  </strong><br />
Table variable is also stored definition into TempDB and if the data volume is increased, sometimes it also stores data into TempDB. </p></blockquote>
<p><strong><code>For that reason, SQL Server 2014 introduced Hekaton storage engine for Memory optimized Table.<br />
<a href="https://www.dbrnd.com/2016/01/sql-server-2014-what-is-hekaton/" target="_blank">"SQL Server 2014: What is Hekaton?"</a><br />
<a href="https://www.dbrnd.com/2016/01/sql-server-2014-create-memory-optimized-file-group-and-table/" target="_blank">"SQL Server 2014: Create Memory Optimized File Group and Table"</a></code></strong></p>
<blockquote><p>If we require creating a unique index on data, we should use Temporary Table. We cannot apply Index on Table Variable. </p></blockquote>
<blockquote><p>If we are dealing with large number records for inserting and deleting, we should use a temporary table. If we have a small quantity of data, we should use Table Variable. </p></blockquote>
<blockquote><p>If the amount of data is frequently changing, query planner requires updated statistics to recompile object so for that we should use Temporary Table.<br />
If the amount of data is not frequently changing, we should use Table Variable for better performance.</p></blockquote>
<blockquote><p>When we require rollback because of an outer user transaction, we should use Table Variable because it automatically discard all the data from the session.</p></blockquote>
<blockquote><p>If we would like to avoid locking issue, we should go with Table Variable because Temp Table is fully dependent on TempDB so sometimes it holds the transactions. </p></blockquote>
<blockquote><p>We can define explicit transaction on Temp Table where with the Table Variable we cannot define explicit transaction.</p></blockquote>
<blockquote><p>The maintenance and creation of metadata for Table Variable requires less time than Temp Table.</p></blockquote>
<blockquote><p>The scope of Table Variable is up to batch or stored procedure after completion of execution it drops automatically.<br />
The scope of Temp Table is up to sessions, and once the session ends, it drops automatically, or we can also drop explicitly. </p></blockquote>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
