<?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>Common Table Expression &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/common-table-expression/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>Tue, 03 Oct 2017 13:21:55 +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: Database Developer (T-SQL) Interview Questions and Answers (Day-3)</title>
		<link>https://www.dbrnd.com/2016/06/sql-server-database-developer-t-sql-interview-questions-and-answers-string-rank-functions-truncate-delete-dynamic-sql-top-clause-cte-day-3/</link>
					<comments>https://www.dbrnd.com/2016/06/sql-server-database-developer-t-sql-interview-questions-and-answers-string-rank-functions-truncate-delete-dynamic-sql-top-clause-cte-day-3/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Tue, 14 Jun 2016 17:46:57 +0000</pubDate>
				<category><![CDATA[SQL Server Interview]]></category>
		<category><![CDATA[answers]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[Common Table Expression]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[Database Developer]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[delete]]></category>
		<category><![CDATA[dense_rank()]]></category>
		<category><![CDATA[interview]]></category>
		<category><![CDATA[OUTPUT clause]]></category>
		<category><![CDATA[questions]]></category>
		<category><![CDATA[RANK]]></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[truncate]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=3039</guid>

					<description><![CDATA[Why is This SQL 3624 Error Caused? This error is basically caused due to bulk insertion in the MS SQL Server which consequently corrupts the transaction log file of that particular database. Ultimately the database is marked as SUSPECT. This SQL error 3624 issue can be a consequence of following situations; Case 1: If a [&#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-string-rank-functions-truncate-delete-dynamic-sql-top-clause-cte-day-3%2F&amp;linkname=SQL%20Server%3A%20Database%20Developer%20%28T-SQL%29%20Interview%20Questions%20and%20Answers%20%28Day-3%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-string-rank-functions-truncate-delete-dynamic-sql-top-clause-cte-day-3%2F&amp;linkname=SQL%20Server%3A%20Database%20Developer%20%28T-SQL%29%20Interview%20Questions%20and%20Answers%20%28Day-3%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-string-rank-functions-truncate-delete-dynamic-sql-top-clause-cte-day-3%2F&amp;linkname=SQL%20Server%3A%20Database%20Developer%20%28T-SQL%29%20Interview%20Questions%20and%20Answers%20%28Day-3%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-string-rank-functions-truncate-delete-dynamic-sql-top-clause-cte-day-3%2F&amp;linkname=SQL%20Server%3A%20Database%20Developer%20%28T-SQL%29%20Interview%20Questions%20and%20Answers%20%28Day-3%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-string-rank-functions-truncate-delete-dynamic-sql-top-clause-cte-day-3%2F&amp;linkname=SQL%20Server%3A%20Database%20Developer%20%28T-SQL%29%20Interview%20Questions%20and%20Answers%20%28Day-3%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-string-rank-functions-truncate-delete-dynamic-sql-top-clause-cte-day-3%2F&amp;linkname=SQL%20Server%3A%20Database%20Developer%20%28T-SQL%29%20Interview%20Questions%20and%20Answers%20%28Day-3%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-string-rank-functions-truncate-delete-dynamic-sql-top-clause-cte-day-3%2F&#038;title=SQL%20Server%3A%20Database%20Developer%20%28T-SQL%29%20Interview%20Questions%20and%20Answers%20%28Day-3%29" data-a2a-url="https://www.dbrnd.com/2016/06/sql-server-database-developer-t-sql-interview-questions-and-answers-string-rank-functions-truncate-delete-dynamic-sql-top-clause-cte-day-3/" data-a2a-title="SQL Server: Database Developer (T-SQL) Interview Questions and Answers (Day-3)"></a></p><p><strong>Why is This SQL 3624 Error Caused?</strong></p>
<blockquote><p>This error is basically caused due to bulk insertion in the MS SQL Server which consequently corrupts the transaction log file of that particular database. Ultimately the database is marked as SUSPECT.</p>
<p>This SQL error 3624 issue can be a consequence of following situations;</p>
<ul>
<li>Case 1: If a table has a non-clustered index.</li>
<li>Case 2: A TABLOCK query hint is used.</li>
<li>Case 3: Prior bulk insertion, table was not truncated.</li>
</ul>
</blockquote>
<p><strong>How you can rename the SQL Server database?</strong></p>
<blockquote><p>Using sp_renamedb system stored procedure, we can rename the SQL Server database.</p></blockquote>
<p><strong>Tell us, most useful FIVE string manipulation functions.</strong></p>
<blockquote><p><strong>CHARINDEX( findTextData, textData, [startingPosition] )</strong> &#8211; Returns the starting position of the specified expression in a character string. The starting position is optional.</p>
<p><strong>REPLACE( textData, findTextData, replaceWithTextData )</strong> &#8211; Replaces occurrences of text found in the string with a new value.</p>
<p><strong>SUBSTRING( textData, startPosition, length )</strong> &#8211; Returns portion of the string.</p>
<p><strong>STUFF( textData, start , length , insertTextData )</strong> &#8211; Deletes a specified length of characters and inserts another set of characters at a specified starting point.</p>
<p><strong>REVERSE( character_expression )</strong> &#8211; Returns the reverse of a character expression.</p>
<p><strong>LEN( textData )</strong> &#8211; Returns integer value of the length of the string, excluding trailing blanks.</p></blockquote>
<p><strong>What is the difference between TRUNCATE and DELETE?</strong></p>
<p><strong>DELETE:</strong></p>
<ul>
<li>DELETE is a DML Command.</li>
<li>DELETE statement is executed using a row lock, each row in the table is locked for deletion.</li>
<li>We can specify filters in where clause</li>
<li>It deletes specified data if where condition exists.</li>
<li>Delete activates a trigger because the operation are logged individually.</li>
<li>Slower than truncate because, it keeps logs.</li>
<li>Rollback is possible.</li>
</ul>
<p><strong>TRUNCATE:</strong></p>
<ul>
<li>TRUNCATE is a DDL command.</li>
<li>TRUNCATE TABLE always locks the table and page but not each row.</li>
<li>Cannot use Where Condition.</li>
<li>It Removes all the data.</li>
<li>TRUNCATE TABLE cannot activate a trigger because the operation does not log individual row deletions.</li>
<li>Faster in performance wise, because it doesn&#8217;t keep any logs.</li>
<li>Rollback is not possible.</li>
</ul>
<p><strong>How you are executing your dynamic SQL?</strong></p>
<ul>
<li>Writing a query with parameters.</li>
<li>Using EXEC.</li>
<li>Using sp_executesql.</li>
</ul>
<p><strong>Can you use TOP clause with UPDATE or DELETE statement?</strong></p>
<blockquote><p>Yes: we can use TOP clause with UPDATE or DELETE statement.</p></blockquote>
<p><strong>What is a TOP WITH TIES option?</strong></p>
<blockquote class="wp-embedded-content" data-secret="h1cdguIqDB"><p><a href="https://www.dbrnd.com/2016/02/sql-server-the-awesome-top-clause-with-ties-option/">SQL Server: The Awesome TOP clause WITH TIES option</a></p></blockquote>
<p><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/02/sql-server-the-awesome-top-clause-with-ties-option/embed/#?secret=h1cdguIqDB" data-secret="h1cdguIqDB" width="600" height="338" title="&#8220;SQL Server: The Awesome TOP clause WITH TIES option&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<p><strong>What is the use of the OUTPUT clause?</strong></p>
<ul>
<li>OUTPUT clause is extension to INSERT, DELETE and UPDATE commands.</li>
<li>It returns rows information those affected by INSERT,UPDATE or DELETE statement.</li>
<li>Its result you can store into variables or other tables for processing.</li>
<li>For INSERT and UPDATE operation use OUTPUT INSERTED.*</li>
<li>For DELETION operation use OUTPUT DELETED.*</li>
<li>is used to select all columns, if you want to select particular column then OUTPUT DELETED.Col1.</li>
</ul>
<p><strong>What do you know about Comman Table Expression (CTE)?</strong></p>
<ul>
<li>A CTE is essentially a disposable view, and can be used in place of derived tables.</li>
<li>CTE is defined by WITH-Keyword, and it is best practice to begin CTE with Semi-column, since CTE is not single-statement it is batch of statement.</li>
<li>CTE can be used in SELECT, INSERT, UPDATE or DELETE statement. But SELECT is desired.</li>
<li>CTE is single-time visible to sub-sequent query only.</li>
<li>CTE can be used to define VIEWS as part of View’s SELECT query.</li>
<li>CTE can be defined as Recursive-CTE or Non-Recursive-CTE;</li>
<li>Recursive-CTE calls itself whereas Non-Recursive does not. It is best practice to use MAXRECURSION to prevent infinite loops in Recursive-CTE.</li>
<li>CTE (Recursive) mainly used for navigating hierarchical data.</li>
<li>CTE (Non-Recursive) is substitutable to derived-table (or Inline-view or Sub-Query); Since CTE and Derived Table are non-persistent and have same visibility.</li>
<li>CTE is not substitutable to Temp-Table or Table-Variable; Because CTE and TempTable are differ based on: Visibility and Persistency; CTE visibility is limited to only a single SQL statement that would very first to it; whereas Temp-Table or Table-Variable is visible to at-least current scope where they defined and Temp-Table are persistent to Db.</li>
<li>CTE can be defined in SUB-ROUTIENS such as user-defined functions, stored procedures triggers or views.</li>
<li>You can define cursor on CTE-referenced Select Query.</li>
</ul>
<p><strong>What are the advantages of CTE?</strong></p>
<blockquote><p><strong>Light-weight:</strong> CTEs are light-weight than Temporary-tables (or Table-Variable). Since, they are non-persistent and do not write any schema information or business-data to disk. The second thing is that CTEs get cleaned up automatically by SQL Server. Therefore, CTE does not create any maintenance over-head and no performance impact.</p>
<p><strong>Recursion:</strong> A recursive-CTE is ultimate for navigating hierarchical data;</p>
<p><strong>Readability:</strong> CTE improves readability; this is awesome aspect that developers always look for. CTE separates data extraction from your main query. Consider a complex query containing multiple joins, data filter operations, group by etc. Using CTE, you can put all JOIN-operations in one CTE-variable; and all filters in another CTE variable then conveniently access them in your query. This will rapidly increase readability of your query. Hence, CTE is substitutable to Derived Table.</p></blockquote>
<p><strong>What are the limitations of CTE?</strong></p>
<ul>
<li>CTE-Select cannot include following clauses:</li>
<li>DISTINCT</li>
<li>INTO</li>
<li>ORDER BY (except when a TOP clause is specified)</li>
<li>GROUP BY</li>
<li>OPTION clause with query hints</li>
<li>FOR BROWSE</li>
<li>CTE-cannot include PIVOTed or Un-PIVOTed data.</li>
</ul>
<p><strong>What is a Recursive Common Table Expression?</strong></p>
<p>A common table expression (CTE) provides the significant advantage of being able to reference itself, thereby creating a recursive CTE. A recursive CTE is one in which an initial CTE is repeatedly executed to return subsets of data until the complete result set is obtained.</p>
<p>A query is referred to as a recursive query when it references a recursive CTE. Returning hierarchical data is a common use of recursive queries.</p>
<p><strong>What do you please tell me something about, RANK() and DENSE_RANK()?</strong></p>
<blockquote><p><strong>RANK():</strong></p>
<ul>
<li>Finds rank of for given column. It increments each row by 1 but skips sub-sequent increments for duplicates.</li>
<li>If repetitive values exist, the same rank would be assigned to all of them.</li>
<li>For each duplicate value, the RANK() function skips the subsequent value so that the next non-duplicate value remains in its rightful position.</li>
</ul>
<p><strong>DENSE_RANK():</strong></p>
<ul>
<li>Finds rank of for given column with subsequent increment even for duplicates.</li>
<li>The main difference between RANK() and DENSE_RANK() is that for duplicates(repetitive) values, RANK() skips sub-sequent rank value</li>
<li>whereas DENSE_RANK() does not skips and continues with next sub-sequent rank.</li>
</ul>
</blockquote>
<p><strong>We require to find a sequential number for each row within a result set. How is this possible?</strong></p>
<blockquote><p>Using ROW_NUMBER() OVER(). It returns the sequential number for each row within a result set, starting from 1.</p>
<p><strong>Syntax:</strong></p>
<p>ROW_NUMBER ( ) OVER ([&lt;partition_by_clause&gt;] &lt;order_by_clause&gt;)</p></blockquote>
<p><strong>Have you ever tried to concat string using GROUP BYclause?</strong></p>
<blockquote class="wp-embedded-content" data-secret="lIpEHgxnUo"><p><a href="https://www.dbrnd.com/2015/12/sql-server-concatenate-strings-using-the-group-by-clause/">SQL Server: Concatenate Strings using the GROUP BY clause</a></p></blockquote>
<p><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2015/12/sql-server-concatenate-strings-using-the-group-by-clause/embed/#?secret=lIpEHgxnUo" data-secret="lIpEHgxnUo" width="600" height="338" title="&#8220;SQL Server: Concatenate Strings using the GROUP BY clause&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<p><strong>How to find maximum value from multiple columns?</strong></p>
<blockquote class="wp-embedded-content" data-secret="TOdBft667Q"><p><a href="https://www.dbrnd.com/2015/12/sql-server-find-max-value-from-multiple-columns/">SQL Server: Find MAX value from Multiple Columns</a></p></blockquote>
<p><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2015/12/sql-server-find-max-value-from-multiple-columns/embed/#?secret=TOdBft667Q" data-secret="TOdBft667Q" width="600" height="338" title="&#8220;SQL Server: Find MAX value from Multiple Columns&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<p><strong>I want to remove all extra spaces from a string, how is it possible?</strong></p>
<blockquote class="wp-embedded-content" data-secret="od1nRDhGpB"><p><a href="https://www.dbrnd.com/2016/01/sql-server-script-to-remove-extra-spaces-from-a-string/">SQL Server: Script to Remove Extra Spaces from a String</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-remove-extra-spaces-from-a-string/embed/#?secret=od1nRDhGpB" data-secret="od1nRDhGpB" width="600" height="338" title="&#8220;SQL Server: Script to Remove Extra Spaces from a String&#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/06/sql-server-database-developer-t-sql-interview-questions-and-answers-string-rank-functions-truncate-delete-dynamic-sql-top-clause-cte-day-3/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</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>
	</channel>
</rss>
