<?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>T-SQL - Techyaz.com</title>
	<atom:link href="https://techyaz.com/tag/t-sql/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>Tips, Tutorials and How-to Topics</description>
	<lastBuildDate>Sat, 24 Jul 2021 18:47:42 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.1</generator>

<image>
	<url>https://techyaz.com/wp-content/uploads/2017/11/cropped-Site-icon-150x150.png</url>
	<title>T-SQL - Techyaz.com</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Learn How to use SQL Server BETWEEN Operator</title>
		<link>https://techyaz.com/sql-server/t-sql/learn-how-to-use-sql-server-between-operator/</link>
					<comments>https://techyaz.com/sql-server/t-sql/learn-how-to-use-sql-server-between-operator/#respond</comments>
		
		<dc:creator><![CDATA[Editorial Staff]]></dc:creator>
		<pubDate>Sat, 17 Jul 2021 16:06:06 +0000</pubDate>
				<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[T-SQL Operators]]></category>
		<guid isPermaLink="false">https://techyaz.com/?p=2563</guid>

					<description><![CDATA[<p>SQL BETWEEN operator is used to get values between a range of data inputs. We can use SQL BETWEEN operator with SELECT, UPDATE, INSERT and DELETE statements. Range can be defined based on text, date or numbers values. Here i&#46;&#46;&#46;</p>
<p>The post <a href="https://techyaz.com/sql-server/t-sql/learn-how-to-use-sql-server-between-operator/">Learn How to use SQL Server BETWEEN Operator</a> appeared first on <a href="https://techyaz.com">Techyaz.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>SQL BETWEEN operator is used to get values between a range of data inputs. We can use SQL BETWEEN operator with SELECT, UPDATE, INSERT and DELETE statements. Range can be defined based on text, date or numbers values. Here i will show you multiple use cases of this operator like get values between two date ranges using SQL BETWEEN operator, get details between two numbers using SQL Server operator BETWEEN etc.</p>



<h2 class="wp-block-heading">Get Values between Two Dates using SQL BETWEEN</h2>



<p>Let&#8217;s say you have a requirement to get all values between two date ranges or specific date time ranges. You can use SQL BETWEEN operator to get this done. Here is the example to get all values between date 19th March 2021 and 20th March 2021. Below example is also an use case of how to use BETWEEN operator in WHERE clause. You can remove &#8216;-&#8216; from date ranges if you want and you can directly mention date ranges as <em>&#8216;20210319&#8217; AND &#8216;20210320&#8217;.</em></p>



<p class="has-text-color" style="color:#0a43eb"><strong>SELECT name, type_desc,create_date, modify_date<br>FROM sys.objects<br>WHERE modify_date BETWEEN &#8216;2021-03-19&#8217; AND &#8216;2021-03-20&#8217;</strong></p>



<p>Here, i have fetched all modified objects on my SQL Server between given date range. Here is the output. We can see there are more than 730 rows returned. You can compare the dates in modify_date column whether output has returned correct data or not. </p>



<figure class="wp-block-image size-large is-style-default"><img fetchpriority="high" decoding="async" width="1024" height="609" src="//i0.wp.com/techyaz.com/wp-content/uploads/2021/07/1-BETWEEN-Operator-1024x609.jpg" alt="SQL BETWEEN Operator with Date ranges" class="wp-image-2580" srcset="https://techyaz.com/wp-content/uploads/2021/07/1-BETWEEN-Operator-1024x609.jpg 1024w, https://techyaz.com/wp-content/uploads/2021/07/1-BETWEEN-Operator-300x178.jpg 300w, https://techyaz.com/wp-content/uploads/2021/07/1-BETWEEN-Operator-768x456.jpg 768w, https://techyaz.com/wp-content/uploads/2021/07/1-BETWEEN-Operator.jpg 1489w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>Now, Next requirement could be to retrieve some data between two date time ranges like you want details between specific time of dates. I will take same above query to show case this example as well. When we don&#8217;t specify the time along with date range then it defaults to 12:00 A.M. </p>



<p class="has-text-color" style="color:#0a43eb"><strong>SELECT name, type_desc,create_date, modify_date<br>FROM sys.objects<br>WHERE modify_date BETWEEN &#8216;2021-03-19 4:38:00&#8217; AND &#8216;2021-03-19 4:38:30&#8217;</strong></p>



<p>Here, i have retrieved all modified objects between 30 seconds of above given time (Time 4:38:00 to 4:38:30). Here is the output and it is showing only 35 rows.</p>



<figure class="wp-block-image size-large is-style-default"><img decoding="async" width="1024" height="608" src="//i0.wp.com/techyaz.com/wp-content/uploads/2021/07/2-BETWEEN-Operator-1024x608.jpg" alt="SQL BETWEEN Operator with two date time ranges" class="wp-image-2581" srcset="https://techyaz.com/wp-content/uploads/2021/07/2-BETWEEN-Operator-1024x608.jpg 1024w, https://techyaz.com/wp-content/uploads/2021/07/2-BETWEEN-Operator-300x178.jpg 300w, https://techyaz.com/wp-content/uploads/2021/07/2-BETWEEN-Operator-768x456.jpg 768w, https://techyaz.com/wp-content/uploads/2021/07/2-BETWEEN-Operator.jpg 1485w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<p>You can use this SQL between two date ranges or datetime ranges to fetch your data. You can use this operator in INSERT, UPDATE or DELETE statements as well.</p>



<h2 class="wp-block-heading">Get Values between Two Numbers</h2>



<p>This section will explain about getting details between two number ranges. Let me take same table which we have taken for above section sys.objects. Now, i want to get all objects having object id between 25 to 30 or you can mention any range. This is just an example to showcase. These number ranges will change as per your need and nature of data. </p>



<p class="has-text-color" style="color:#0a43eb"><strong>SELECT name, object_id, type_desc, create_date<br>FROM sys.objects<br>WHERE object_id BETWEEN &#8217;25&#8217; AND &#8217;30&#8217;</strong></p>



<p>Note, above object_id is column name and not the T-SQL function. Have a look at its output in below image. We have got only rows which are assigned with these object ids.</p>



<figure class="wp-block-image size-large is-style-default"><img decoding="async" width="500" height="305" src="//i0.wp.com/techyaz.com/wp-content/uploads/2021/07/3-BETWEEN-Operator.jpg" alt="SQL BETWEEN Operator with number ranges" class="wp-image-2582" srcset="https://techyaz.com/wp-content/uploads/2021/07/3-BETWEEN-Operator.jpg 500w, https://techyaz.com/wp-content/uploads/2021/07/3-BETWEEN-Operator-300x183.jpg 300w" sizes="(max-width: 500px) 100vw, 500px" /></figure>



<h2 class="wp-block-heading">Use BETWEEN with NOT Operator</h2>



<p>Above all examples shows how to get data between two ranges but we can use NOT operator with BETWEEN to return all values which is not between specified two ranges. Let&#8217;s take above example where BETWEEN operator has returned only 5 rows based on their specified two ranges. Now if i will use NOT operator in above T-SQL statement then output will return all rows of table sys.objects except above 4 rows which will be prevented by NOT operator. Let me show you this example.</p>



<p class="has-text-color" style="color:#0a43eb"><strong>SELECT name, object_id, type_desc, create_date<br>FROM sys.objects<br>WHERE object_id NOT BETWEEN &#8217;25&#8217; AND &#8217;30&#8217;</strong></p>



<p>Have  a look at below highlighted are where objects ids between 25 to 30 are missing.</p>



<figure class="wp-block-image size-large is-style-default"><img loading="lazy" decoding="async" width="547" height="597" src="//i0.wp.com/techyaz.com/wp-content/uploads/2021/07/4-BETWEEN-Operator.jpg" alt="SQL BETWEEN Operator with NOT operator" class="wp-image-2583" srcset="https://techyaz.com/wp-content/uploads/2021/07/4-BETWEEN-Operator.jpg 547w, https://techyaz.com/wp-content/uploads/2021/07/4-BETWEEN-Operator-275x300.jpg 275w" sizes="auto, (max-width: 547px) 100vw, 547px" /></figure>



<p>Here, i have shown you few use cases of SQL Server T-SQL operator BETWEEN statement. You can go head and try this operator for your business needs. For more information on this operator, visit <a href="https://docs.microsoft.com/en-us/sql/t-sql/language-elements/between-transact-sql?view=sql-server-ver15" target="_blank" rel="noreferrer noopener">MSDN</a> article.</p>



<p class="has-vivid-red-color has-text-color"><strong><em>Read More</em></strong></p>



<ul class="wp-block-list"><li><strong><a href="https://techyaz.com/sql-server/troubleshooting/fixview-server-state-permission-was-denied-on-object-server-database-master/" target="_blank" rel="noreferrer noopener">Fix:VIEW SERVER STATE permission was denied on object ‘server’, database ‘master’</a></strong></li><li><strong><a href="https://techyaz.com/sql-server/t-sql/difference-between-union-and-union-all-operators/" target="_blank" rel="noreferrer noopener">Difference between UNION and UNION ALL T-SQL Operators</a></strong></li><li><a href="https://techyaz.com/interview-questions/sql-server-interview-questions/sql-server-interview-questions-answers-indexes/" target="_blank" rel="noreferrer noopener"><strong>SQL Server Interview Questions &amp; Answers on Indexes</strong></a></li></ul>



<p></p>
<p>The post <a href="https://techyaz.com/sql-server/t-sql/learn-how-to-use-sql-server-between-operator/">Learn How to use SQL Server BETWEEN Operator</a> appeared first on <a href="https://techyaz.com">Techyaz.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://techyaz.com/sql-server/t-sql/learn-how-to-use-sql-server-between-operator/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Fix Error 1105: Could not allocate space for object in database because the filegroup is full.</title>
		<link>https://techyaz.com/sql-server/troubleshooting/fix-error-1105/</link>
					<comments>https://techyaz.com/sql-server/troubleshooting/fix-error-1105/#respond</comments>
		
		<dc:creator><![CDATA[Manvendra Deo Singh]]></dc:creator>
		<pubDate>Mon, 16 Apr 2018 06:40:16 +0000</pubDate>
				<category><![CDATA[SQL Server Administration]]></category>
		<category><![CDATA[Troubleshooting]]></category>
		<category><![CDATA[HowTO]]></category>
		<category><![CDATA[log space]]></category>
		<category><![CDATA[space issues]]></category>
		<category><![CDATA[SQL_Error_Code]]></category>
		<category><![CDATA[T-SQL]]></category>
		<guid isPermaLink="false">http://techyaz.com/?p=2090</guid>

					<description><![CDATA[<p>Today, I got error 1105 on one of the database server. We were processing some bulk transactions on a database but failed because of space issue. Full description of error 1105 is given below. Error 1105, Severity 17, State 2&#46;&#46;&#46;</p>
<p>The post <a href="https://techyaz.com/sql-server/troubleshooting/fix-error-1105/">Fix Error 1105: Could not allocate space for object in database because the filegroup is full.</a> appeared first on <a href="https://techyaz.com">Techyaz.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Today, I got error 1105 on one of the database server. We were processing some bulk transactions on a database but failed because of space issue. Full description of error 1105 is given below.</p>
<p><em><span style="color: #ff0000;">Error 1105, Severity 17, State 2</span></em><br />
<em><span style="color: #ff0000;"> Could not allocate space for object &#8216;Object_Name’ in database &#8216;DB_Name’ because the &#8216;Primary’ filegroup is full. Create disk space by deleting unneeded files, dropping objects in the filegroup, adding additional files to the filegroup, or setting autogrowth on for existing files in the filegroup.</span></em></p>
<h3><span style="color: #333399;">Error 1105 – Root Cause</span></h3>
<p>As error suggests, this issue was generated because database was not able to allocate space anymore. Whenever you get such space issue, all transactions will be stopped until you make some room in the database. All transactions will be stopped because of non availability of space because none of the transaction will get any space to proceed their transactions. There are many reasons you can get space issues. Some of them are:</p>
<p><img loading="lazy" decoding="async" class="size-full wp-image-2091 alignright" src="http://techyaz.com/wp-content/uploads/2018/04/Error-1105.png" alt="error 1105" width="300" height="300" srcset="https://techyaz.com/wp-content/uploads/2018/04/Error-1105.png 300w, https://techyaz.com/wp-content/uploads/2018/04/Error-1105-150x150.png 150w, https://techyaz.com/wp-content/uploads/2018/04/Error-1105-160x160.png 160w, https://techyaz.com/wp-content/uploads/2018/04/Error-1105-320x320.png 320w" sizes="auto, (max-width: 300px) 100vw, 300px" /></p>
<ul>
<li>Data or Log drive is full.</li>
<li>Database file/s has restricted file growth</li>
<li>Database File Autogrowth is not enabled.</li>
<li>Some tables are growing faster than our prediction.</li>
<li>Some long running transaction is eating all space.</li>
</ul>
<p>We generally get error 1105 when any database including tempdb or any transaction log file get full and runs out of space. File growth restriction is also a possible reason you can get error 1105. Make sure to check all database files associated with your database to make sure there is no file growth restriction is set that is causing to generate this error. Sometimes when you restrict the file growth and the file size reached its limit, you may get this error message when trying insert / updates on database. I have explained multiple solutions to overcome this issue. Have a look at below section to get the solution of such space issues.</p>
<h3><span style="color: #333399;">Solution</span></h3>
<p>To fix this error we need to make space in the database so that all running transactions can execute and log their operations. We have multiple solutions to fix such issue based on the nature of the issues. Some of the solutions are given below:</p>
<ul>
<li>First you should check if any unwanted file is not there in data or log drive. Sometimes we placed backup files in data or log drive and forgot to delete it. Make sure to remove or move such unwanted files to make space for your database.</li>
<li>If any of the database files have restricted file growth then you should immediately turn on autogrow feature of the data or log file. You can read below article to understand what should be the perfect value for autogrowth of a data or log file.</li>
</ul>
<p style="padding-left: 90px;"><strong><u><a href="http://techyaz.com/sql-server/understanding-database-autogrowth-sql-server/" target="_blank" rel="noopener">How to Enable Autogrowth and What should be the Best value for File Autogrowth?</a></u></strong></p>
<ul>
<li>If size of your database file is limited to some value then make sure to extend the size of that file or I would suggest going with unrestricted growth. Read above attached article to get more about this.</li>
<li>If your data or log drive is running out of space then you should add more files to the file group on different drive where you have enough space. You can use below command to add any data or log file to your desired drive. Make sure to change the drive path as per your correct path.</li>
</ul>
<pre style="padding-left: 60px;"><strong><span style="color: #0000ff;">ALTER DATABASE Techyaz</span></strong>
<strong><span style="color: #0000ff;">ADD FILE (</span></strong>
<strong><span style="color: #0000ff;">NAME = techyaz_Data3,</span></strong>
<strong><span style="color: #0000ff;">FILENAME = 'F:\MSSQL\DATA\techyaz_DataFile3.ndf')</span></strong></pre>
<ul>
<li>We can also free disk space by dropping index or tables that are no longer needed. You can also consider data purging for unwanted tables or indexes.</li>
<li>You can also consider moving some of the database files to different drive to make some space for your database.</li>
</ul>
<p>I hope you like this article. Please follow our <a href="https://www.facebook.com/Techyaz/">Facebook</a> page and <a href="https://twitter.com/Tech_yaz">Twitter</a> handle to get latest updates.</p>
<p><span style="color: #800000;"><em><strong>Read More:</strong></em></span></p>
<ul>
<li><strong><a href="http://techyaz.com/sql-server/troubleshooting/fix-error-1101-could-not-allocate-a-new-page-for-database/" target="_blank" rel="noopener">Fix Error 1101: Could not allocate a new page for database</a></strong></li>
<li><strong><a href="http://techyaz.com/sql-server/avoid-database-shrink-operation/" target="_blank" rel="noopener">Why should we Avoid Database Shrink Operation?</a></strong></li>
<li><strong><a href="http://techyaz.com/sql-server/always-turn-off-database-auto-shrink/" target="_blank" rel="noopener">Why should we always Disable Autoshrink property?</a></strong></li>
</ul>
<p>The post <a href="https://techyaz.com/sql-server/troubleshooting/fix-error-1105/">Fix Error 1105: Could not allocate space for object in database because the filegroup is full.</a> appeared first on <a href="https://techyaz.com">Techyaz.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://techyaz.com/sql-server/troubleshooting/fix-error-1105/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>New T-SQL Functions Introduced in SQL Server 2017</title>
		<link>https://techyaz.com/sql-server/t-sql/new-t-sql-functions-introduced-sql-server-2017/</link>
					<comments>https://techyaz.com/sql-server/t-sql/new-t-sql-functions-introduced-sql-server-2017/#respond</comments>
		
		<dc:creator><![CDATA[Manvendra Deo Singh]]></dc:creator>
		<pubDate>Fri, 09 Feb 2018 16:19:25 +0000</pubDate>
				<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[New features in SQL Server 2017]]></category>
		<category><![CDATA[T-SQL functions]]></category>
		<guid isPermaLink="false">http://techyaz.com/?p=1776</guid>

					<description><![CDATA[<p>SQL Server 2017 is feature rich product that has been launched with multiple new features. You can read attached article where I have explained Top 10 new features added in SQL Server 2017 database engine. I have also explained about&#46;&#46;&#46;</p>
<p>The post <a href="https://techyaz.com/sql-server/t-sql/new-t-sql-functions-introduced-sql-server-2017/">New T-SQL Functions Introduced in SQL Server 2017</a> appeared first on <a href="https://techyaz.com">Techyaz.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>SQL Server 2017 is feature rich product that has been launched with multiple new features. You can read attached article where I have explained<strong> <a href="http://techyaz.com/sql-server/10-new-features-sql-server-2017-database-engine/" target="_blank" rel="noopener">Top 10 new features added in SQL Server 2017 database engine</a>.</strong> I have also explained about new T-SQL functions introduced in SQL Server 2017 (CONCAT_WS, TRANSLATE, TRIM, STRING_AGG) in attached article. Here, I will explain these new T-SQL functions with examples and their use cases.</p>
<p><img loading="lazy" decoding="async" class="size-full wp-image-1790 alignright" src="http://techyaz.com/wp-content/uploads/2018/02/New-in-SQL-2017.png" alt="New T-SQL Functions in SQL 2017" width="300" height="300" srcset="https://techyaz.com/wp-content/uploads/2018/02/New-in-SQL-2017.png 300w, https://techyaz.com/wp-content/uploads/2018/02/New-in-SQL-2017-150x150.png 150w, https://techyaz.com/wp-content/uploads/2018/02/New-in-SQL-2017-160x160.png 160w, https://techyaz.com/wp-content/uploads/2018/02/New-in-SQL-2017-320x320.png 320w" sizes="auto, (max-width: 300px) 100vw, 300px" /></p>
<p>There are four new T-SQL functions introduced in SQL Server 2017. These are very useful that make SQL Server developers life easier. Let’s have a look at each one of these SQL 2017 new  functions with their examples and use cases.</p>
<h3><span style="color: #333399;">CONCAT_WS</span></h3>
<p>If you look at the name of this function <strong><em>CONCAT_WS</em></strong> then it will come out as <em><strong>concatenate with separator.</strong></em> This function requires a separator specified as 1<sup>st</sup> argument and minimum of two or more arguments mentioned as remaining arguments. All arguments will be concatenated into a single string with a separator specified in the 1st argument. Null values are ignored during concatenation, and does not add the separator.</p>
<p>Below are the examples of this new function. Suppose, you want to gather login details that has sysadmin access on your SQL Server Instance in a separator format then you can use below command to get these details. You can change the columns of this command or you can also change the T-SQL command if you want to gather some other information. You can also change the separator comma mentioned in first argument to some other separator as per your wish.</p>
<pre><strong><span style="font-size: medium; color: #0000ff;">SELECT CONCAT_WS (‘,’, name, status, sysadmin) As LoginDetails from syslogins
</span></strong></pre>
<p>The output of above command will look like below details.</p>
<pre><span style="color: #000000;"><strong><span style="font-size: medium;"><u>LoginDetails</u>

Sa,9,1
techyaz\test1,10,1
techyaz\deo1,9,0
ty1,9,0
</span></strong></span></pre>
<p>As I said above, this function skips the null values. You can see this by running below command on your SQL Server 2017 instance.</p>
<pre><strong><span style="font-size: medium; color: #0000ff;">SELECT CONCAT_WS(',',132, NULL, NULL, 'Urban Estate', 'Gurgaon', 122001) AS Address; </span></strong></pre>
<p>Output of above command will be:</p>
<pre><span style="color: #000000;"><strong><span style="font-size: medium;"><u>Address</u>

132,Urban Estate, Gurgaon, 122001
</span></strong></span></pre>
<p>You can see null values have been skipped in above output.</p>
<h3><span style="color: #333399;">TRANSLATE</span></h3>
<p>Another useful T-SQL function introduced in SQL Server 2017 is <strong><em>TRANSLATE</em></strong>. This function returns a string given in first argument after some characters given in second argument translated with the characters given in third arguments.</p>
<p>Here, you need to give three inputs. Input string is first argument that we want to modify with some changes. Second Argument is characters that is an expression of any character type containing characters that should be replaced. Third argument is an expression that will replace second argument mentioned in Inputstring. Make sure that the length and type of characters and translations will be same otherwise you will end up with errors. The output will be same as given in input string if you pass NULL value in any of the second or third argument.</p>
<p>Below is the example of this function.</p>
<pre><span style="color: #0000ff;"><strong><span style="font-size: medium;">SELECT TRANSLATE ('[7.124, 9.6]' , '[,]', '( )') AS Values,
</span></strong></span></pre>
<p>Here we are replacing a square bracket having comma with regular bracket and blank space in place of comma.   Output of above T-SQL will be given below.</p>
<pre><span style="color: #000000;"><strong><span style="font-size: medium;"><u>Values</u>

(7.124 9.6)
</span></strong></span></pre>
<p>You can see square bracket has been replaced with the given one and comma separator is also removed from above expression. If you want to revert it of you want to enter comma or any separator with changing the give brackets you can also get this done using this function.</p>
<pre><span style="color: #0000ff;"><strong><span style="font-size: medium;">SELECT TRANSLATE('(7.124 9.6)' , '( )', '[,]') AS Values;
</span></strong></span></pre>
<p>Output of above command will look like below information.</p>
<pre><span style="color: #000000;"><strong><span style="font-size: medium;"><u>Values</u>

[7.124,9.6]

</span></strong></span></pre>
<p>Another example of this function is given below. Run below t-sql command if you want to replace few to the brackets with the given in transactions argument.</p>
<pre><span style="color: #0000ff;"><strong><span style="font-size: medium;">SELECT TRANSLATE('[4+2]/{6-2}', '[]{}', '()()') As Formula;
</span></strong></span></pre>
<p>The output of above command will be look like below info.</p>
<pre><span style="color: #000000;"><strong><span style="font-size: medium;"><u>Formula</u>

(4+2)/(6-2)
</span></strong></span></pre>
<h3><span style="color: #333399;">TRIM</span></h3>
<p>This function has enabled users to remove the space characters or other characters from the start or end of the string. Earlier we used to do the same thing using <em><strong>LTRIM(RTRIM(@string))</strong></em> T-SQL command.</p>
<p>Below example will remove the free spaces given before and after the word techyaz.</p>
<pre><span style="color: #0000ff;"><strong><span style="font-size: medium;">SELECT TRIM( '             techyaz              ') AS Result;
</span></strong></span></pre>
<p>We can the output of above t-sql function given as:</p>
<pre><strong><span style="font-size: medium; color: #000000;">Techyaz
</span></strong></pre>
<p>Earlier we used to do the same thing using below t-sql command.</p>
<pre><span style="color: #0000ff;"><strong><span style="font-size: medium;">LTRIM(RTRIM('    techyaz    '))</span></strong></span></pre>
<h3><span style="color: #333399;">STRING_AGG</span></h3>
<p>Many developers were expected this function to be part of SQL Server since long time. Now their wish have been completed in SQL Server 2017. <strong><em>STRING_AGG</em></strong> is going to become very popular among all new functions. This function concatenates the values of string expressions and places separator values between them. The separator is not added at the end of string.</p>
<p><em><strong>STRING_AGG</strong></em> is an aggregate function that takes all expressions from rows and concatenates them into a single string. Here is the example where we will see output from a table in a given format.</p>
<pre><strong><span style="font-size: medium; color: #0000ff;">SELECT STRING_AGG(CONCAT(FirstName, ' ', LastName, ' (', ModifiedDate, ')'), CHAR(13))
AS names
FROM Person.Person;
</span></strong></pre>
<p>Output of above command will look like:</p>
<pre><span style="color: #000000;"><strong><span style="font-size: medium;"><u>Names</u>

Manvendra Singh (Feb 8 2018 12:00AM)
Maruti Nandan (Dec 24 2017 12:00AM)
Angelo M (Feb 5 2018 12:00AM)
</span></strong></span></pre>
<p>You can see all column values are showing a single string in each row. Another aspect of this function is given in below example.</p>
<p>Suppose, you have a database having information about your blog or published articles. There are separate tables to save articles and their tags. Now, developers want to return one row per each article with all associated tags. We can use below query to get the output.</p>
<pre><span style="color: #0000ff;"><strong><span style="font-size: medium;">SELECT a.ArticleId, Title, STRING_AGG (tag, ',') as Tags
FROM dbo.Article AS a
LEFT JOIN dbo.ArticleTag AS t
ON a.ArticleId = t.ArticleId
GROUP BY a.articleId, title;
</span></strong></span></pre>
<p>Output of above command will look like below details.</p>
<table width="716">
<thead>
<tr>
<td><span style="color: #000000;"><strong>ArticleId</strong></span></td>
<td><span style="color: #000000;"><strong>Title</strong></span></td>
<td><span style="color: #000000;"><strong>Tags</strong></span></td>
</tr>
</thead>
<tbody>
<tr>
<td><span style="color: #000000;"><strong>69</strong></span></td>
<td><span style="color: #000000;"><strong>How to Check IP Address in Linux</strong></span></td>
<td><span style="color: #000000;"><strong>Linux,ip,rhel,howto</strong></span></td>
</tr>
<tr>
<td><span style="color: #000000;"><strong>70</strong></span></td>
<td><span style="color: #000000;"><strong>How to Learn SQL Server DBA</strong></span></td>
<td><span style="color: #000000;"><strong>Learning</strong></span></td>
</tr>
<tr>
<td><span style="color: #000000;"><strong>71</strong></span></td>
<td><span style="color: #000000;"><strong>What is Pages and Extents</strong></span></td>
<td><span style="color: #000000;"><strong>Page,extent,datafiles,db</strong></span></td>
</tr>
</tbody>
</table>
<p>Here, I have described new T-SQL functions introduced in SQL Server 2017 with their examples. I hope you like this article. Please follow our <a href="https://www.facebook.com/Techyaz/">Facebook</a> page and <a href="https://twitter.com/Tech_yaz">Twitter</a> handle to get latest updates.</p>
<p><em><strong><span style="color: #800000;">Read More:</span></strong></em></p>
<ul>
<li><strong><a href="http://techyaz.com/sql-server/difference-between-union-and-union-all-operators/" target="_blank" rel="noopener">What is the Difference between UNION and UNION ALL T-SQL Operators?</a></strong></li>
<li><strong><a href="http://techyaz.com/sql-server/understanding-different-types-sql-joins-examples/" target="_blank" rel="noopener">Understanding Different types of SQL JOINs with their Examples</a></strong></li>
<li><strong><a href="http://techyaz.com/sql-server/get-row-counts-tables-database/" target="_blank" rel="noopener">How to get Total Row Count of all tables of a database</a></strong></li>
<li><strong><a href="http://techyaz.com/sql-server/how-to-disable-auto-commit-in-sql-server/" target="_blank" rel="noopener">How to Disable AutoCommit in SQL Server?</a></strong></li>
</ul>
<p>&nbsp;</p>
<p>The post <a href="https://techyaz.com/sql-server/t-sql/new-t-sql-functions-introduced-sql-server-2017/">New T-SQL Functions Introduced in SQL Server 2017</a> appeared first on <a href="https://techyaz.com">Techyaz.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://techyaz.com/sql-server/t-sql/new-t-sql-functions-introduced-sql-server-2017/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Disk and Performance Impact of Online Index Rebuild Operation</title>
		<link>https://techyaz.com/sql-server/indexes/performing-online-index-rebuild-operation/</link>
					<comments>https://techyaz.com/sql-server/indexes/performing-online-index-rebuild-operation/#respond</comments>
		
		<dc:creator><![CDATA[Manvendra Deo Singh]]></dc:creator>
		<pubDate>Fri, 29 Dec 2017 12:18:51 +0000</pubDate>
				<category><![CDATA[Indexes]]></category>
		<category><![CDATA[Performance Tuning]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server Administration]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[Clustered Index]]></category>
		<category><![CDATA[Index]]></category>
		<category><![CDATA[index rebuild]]></category>
		<category><![CDATA[Nonclustered Index]]></category>
		<category><![CDATA[SQL Server Indexes]]></category>
		<guid isPermaLink="false">http://techyaz.com/?p=1421</guid>

					<description><![CDATA[<p>Here, we are going to talk about disk and performance Impact of online Index rebuild operation. As we know index rebuild is offline operation due to which indexes become inaccessible. Here, I will describe about SQL Server rebuild index online&#46;&#46;&#46;</p>
<p>The post <a href="https://techyaz.com/sql-server/indexes/performing-online-index-rebuild-operation/">Disk and Performance Impact of Online Index Rebuild Operation</a> appeared first on <a href="https://techyaz.com">Techyaz.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Here, we are going to talk about disk and performance Impact of online Index rebuild operation. As we know index rebuild is offline operation due to which indexes become inaccessible. Here, I will describe about SQL Server rebuild index online that will keep SQL Server indexes accessible. I hope you are aware about the<strong> <a href="http://techyaz.com/sql-server/difference-index-rebuild-reorganize/" target="_blank" rel="noopener">difference between Index rebuild and Index reorganize operation</a>.</strong> If you are not aware please have a look at attached article. Index Reorganize is already an online operation whereas Index rebuild can be done using offline as well as online method. Performing online index operations include index creation, index rebuild and drop indexes. I will describe online rebuild index operation and its impact on disk and performance in this article and same concept will be applied to online index creation and online indexe drop as well.</p>
<p>There is new feature called <em>Resumable Online Index Rebuild</em> introduced in SQL Server 2017 that is an extension of online index rebuild operation. Learn about<strong> <a href="http://techyaz.com/sql-server/use-resumable-online-index-rebuild-operation-sql-server/" target="_blank" rel="noopener">Resumable Online Index Rebuild</a></strong> operation in SQL Server 2017 in attached article.</p>
<p><em><span style="color: #800000;"><strong>Read More:</strong></span></em></p>
<ul>
<li><strong><a href="http://techyaz.com/sql-server/what-should-be-the-best-value-for-fill-factor-in-sql-server/" target="_blank" rel="noopener">What should be best value for fill factor in SQL Server?</a></strong></li>
<li><strong><a href="http://techyaz.com/sql-server/how-to-avoid-page-split-in-sql-server/" target="_blank" rel="noopener">How to Avoid Page Split in SQL Server?</a></strong></li>
<li><strong><a href="http://techyaz.com/sql-server/use-resumable-online-index-rebuild-operation-sql-server/" target="_blank" rel="noopener">How to use Resumable Online Rebuild Operation?</a></strong></li>
</ul>
<h3><span style="color: #333399;">ONLINE Index Rebuild Operation</span></h3>
<p>Rebuilding an index drops and re-creates the index. Indexes becomes unavailable during this exercise that causes an outage for that object. Microsoft has given a solution to avoid inaccessibility of the object during index rebuild operation. We can specify ONLINE keyword value as ON in CREATE INDEX or ALTER INDEX to rebuild indexes online.</p>
<p><img loading="lazy" decoding="async" class="size-full wp-image-1423 alignleft" src="http://techyaz.com/wp-content/uploads/2017/12/Perform-Online-Index-Operations.png" alt="Online index operation" width="560" height="315" srcset="https://techyaz.com/wp-content/uploads/2017/12/Perform-Online-Index-Operations.png 560w, https://techyaz.com/wp-content/uploads/2017/12/Perform-Online-Index-Operations-300x169.png 300w" sizes="auto, (max-width: 560px) 100vw, 560px" /></p>
<p>When you are rebuilding an index and the ONLINE option is set to ON, the underlying objects, the tables and associated indexes, are available for queries and data modification. Row versioning is used to allow for transactional consistency. SQL Server reindex ONLINE option does not work if your table has BLOB data types or index is an XML index or Spatial index.</p>
<p>I have given the list of T-SQL statements that will rebuild indexes ONLINE on your table. You just need to change the index name, table name and column name from below statements.</p>
<p>Below SQL code will rebuild the clustered index on column <strong>EMPID</strong> on the table <strong>dbo.Salary</strong>. As we are rebuilding this cluster index using dropping and recreating the cluster indexes so existing index will be dropped in the process, but it will be available during the operation because the ONLINE option is specified.</p>
<pre class="brush:sql;"><strong><span style="color: #0000ff;">CREATE CLUSTERED INDEX CI_Salary_EMPID ON dbo.Salary(EMPID)
WITH(DROP_EXISTING = ON, ONLINE = ON)
</span></strong></pre>
<p>We can also use ALTER INDEX statement to rebuild a specific index or all indexes on a specified table. The ONLINE syntax remains the same as the CREATE INDEX statement if you want to run this operation online.</p>
<pre class="brush:sql;"><strong><span style="color: #0000ff;">ALTER INDEX ALL ON [dbo.Salary]
REBUILD WITH(ONLINE = ON)
</span></strong></pre>
<p>Above statement will rebuild all indexes on table Salary keeping everything accessible during this operation. Now, we can also rebuild clustered index only on the dbo.Salary table. The ONLINE option is specified, which means that the table will be accessible during the rebuild operation.</p>
<pre class="brush:sql;"><strong><span style="color: #0000ff;">ALTER INDEX CI_Salary_EMPID ON dbo.salary
REBUILD WITH(ONLINE = ON)
</span></strong></pre>
<p>But if we will remove ONLINE option from above statement, then table will NOT be accessible during rebuild operation. You can run below command to validate the accessibility of your table for which you are rebuilding the indexes.</p>
<pre class="brush:sql;"><strong><span style="color: #0000ff;">ALTER INDEX CI_Salary_EMPID ON dbo.salary
REBUILD
</span></strong></pre>
<h3><span style="color: #333399;">Disk Space Considerations </span></h3>
<p>Disk space is an important consideration when you create, rebuild, or drop indexes. Inadequate disk space can degrade performance or even cause the index operation to fail. There might be other major performance impact of Online Index Rebuild operation as well. Please consider below recommendations if you are using Online index operations or during SQL Server rebuild index online.</p>
<ol>
<li>During ONLINE index rebuild and index creation, additional space is required in the data file to keep the second copy of the index. This is because SQL Server creates a snapshot of the index and once index rebuild or creation completes, second copy of this index will be removed by SQL Server.</li>
<li>Additional disk space is required for the temporary mapping index. This temporary index is used in online index operations that create, rebuild, or drop a clustered index.</li>
<li>Make sure the transaction log has been backed up and truncated before running index operations online, and that the log has sufficient space to store the projected index and user transactions.</li>
<li>Specify SORT_IN_TEMPDB option to ON for the index operation. This separates the index transactions from the concurrent user transactions. The index transactions will be stored in the tempdb transaction log, and the concurrent user transactions will be stored in the transaction log of the user database. Make sure to keep tempdb log and user database log files on separate drives to avoid any disk space issues.</li>
<li>Verify that the tempdb database and transaction log have sufficient disk space to handle the index operation. The tempdb transaction log cannot be truncated until the index operation is completed.</li>
<li>Do not run the online index operation in an explicit transaction. The log will not be truncated until the explicit transaction ends.</li>
</ol>
<h3><span style="color: #333399;">Performance Considerations</span></h3>
<p>If we think about performance impact of Online Index Rebuild operation on SQL Server then it will put more burden on your database server than offline index operations. Because both the source and target structures are maintained during the online index operation.</p>
<p>ONLINE Index operations will be slower than equivalent offline index operations because insert, update, and delete transactions is increased, potentially up to double. This could cause a decrease in performance and greater resource usage, especially CPU time, during the index operation. Online index operations are enterprise features and are fully logged operations.</p>
<p>It is recommended to use legacy way of index rebuild or index operations if your system allows a maintenance window. Remember users will be restricted to access data during the offline index operation, but the operation finishes faster and uses fewer resources.</p>
<p>If you have a system that runs 24&#215;7 then ONLINE index rebuild or creation will be a better choice but make sure to consider all points described in this article before choosing online index operations. You need to think from disk space and performance both prospect and design your system that can handle the load and sustain during peak hours.</p>
<p><em><span style="color: #800000;"><strong>Related Articles</strong></span></em></p>
<ul>
<li><strong><a href="http://techyaz.com/sql-server/sql-server-interview-questions-answers-indexes/" target="_blank" rel="noopener">SQL Server Interview Questions &amp; Answers on Indexes</a></strong></li>
<li><strong><a href="http://techyaz.com/sql-server/understanding-sql-server-indexes/" target="_blank" rel="noopener">Understanding Different types of Indexes in SQL Server</a></strong></li>
</ul>
<p>Here, I have described Disk and Performance Impact of Online Index Rebuild operation on SQL Server. I hope you like this article. Please follow our <a href="https://www.facebook.com/Techyaz/">Facebook</a> page and <a href="https://twitter.com/Tech_yaz">Twitter </a>handle to get latest updates.</p>
<p>The post <a href="https://techyaz.com/sql-server/indexes/performing-online-index-rebuild-operation/">Disk and Performance Impact of Online Index Rebuild Operation</a> appeared first on <a href="https://techyaz.com">Techyaz.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://techyaz.com/sql-server/indexes/performing-online-index-rebuild-operation/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Understanding Different Types of SQL JOINs with Examples</title>
		<link>https://techyaz.com/sql-server/t-sql/understanding-different-types-sql-joins-examples/</link>
					<comments>https://techyaz.com/sql-server/t-sql/understanding-different-types-sql-joins-examples/#respond</comments>
		
		<dc:creator><![CDATA[Maruti Nandan]]></dc:creator>
		<pubDate>Thu, 14 Dec 2017 08:38:18 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[Joins]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[tsql]]></category>
		<guid isPermaLink="false">http://techyaz.com/?p=1343</guid>

					<description><![CDATA[<p>SQL JOINs are used to retrieve set of information from two or more different tables based upon certain common values between them. We use joins to combine tables with Select SQL statements. Related Articles: Read UNION vs UNION ALL Logon&#46;&#46;&#46;</p>
<p>The post <a href="https://techyaz.com/sql-server/t-sql/understanding-different-types-sql-joins-examples/">Understanding Different Types of SQL JOINs with Examples</a> appeared first on <a href="https://techyaz.com">Techyaz.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>SQL JOINs are used to retrieve set of information from two or more different tables based upon certain common values between them. We use joins to combine tables with Select SQL statements.</p>
<p><em><strong><span style="color: #800000;">Related Articles:</span></strong></em></p>
<ul>
<li><strong><a href="https://techyaz.com/sql-server/difference-between-union-and-union-all-operators/" target="_blank" rel="noopener">Read UNION vs UNION ALL</a></strong></li>
<li><strong><a href="https://techyaz.com/sql-server/create-logon-trigger-restrict-sysadmin-logins-connect-sql-server-given-time-interval/" target="_blank" rel="noopener">Logon Trigger to Restrict sysadmin logins</a></strong></li>
<li><strong><a href="https://techyaz.com/sql-server/troubleshooting/table-row-count-showing-incorrect-value-sys-partitions-dmv-sys-dm_db_partition_stats/" target="_blank" rel="noopener">Why rou count showing incorrect value in sys.partitions?</a></strong></li>
</ul>
<h3><span style="color: #333399;"><strong>Types of Joins</strong></span></h3>
<p><strong> </strong>There are four types of Joins and each type is having separate ways to retrieve data.</p>
<ul>
<li><strong>Inner Join</strong></li>
<li><strong>Right Join</strong></li>
<li><strong>Left Join</strong></li>
<li><strong>Full Join</strong></li>
</ul>
<p>We will use two tables Employees and Leavesdetails to explain you each type of Joins with example. The details of both tables are given below.</p>
<p><strong>Table Employees:</strong></p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-1345" src="http://techyaz.com/wp-content/uploads/2017/12/1-Employees-Table.png" alt="Employees Table" width="378" height="196" /></p>
<p><strong>Table LeavesDetails:</strong></p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-1346" src="http://techyaz.com/wp-content/uploads/2017/12/2-LeaveDetails-Table.png" alt="LeavesDetails Table" width="380" height="194" /></p>
<p><strong> </strong>We will apply all types of Joins between these two tables to show you how they work. Let&#8217;s start with Inner Join.<strong> </strong></p>
<h5><span style="color: #333399;"><strong>Inner Join</strong><strong> </strong></span></h5>
<p>Inner join will show data that is matched between both joined tables. This is default join where result is based upon where clause and matched value from all rows fetch data. The visual representation of inner join will look like below image. You can see the coloured area that is common between both tables and that will be output of INNER JOIN.</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-1347 " src="http://techyaz.com/wp-content/uploads/2017/12/3-Inner-Join.png" alt="Inner Join" width="244" height="150" /></p>
<p>As per above image, both tables Employees and Leavesdetails have been joined together to get output details for rows that are matched to each other.</p>
<pre><strong><span style="color: #0000ff;">SELECT *
FROM EMPLOYEES
<em>INNER JOIN</em> [dbo].[LeavesDetails]
ON [LeaveDetails].[Employeeid]=[Employees].[Employeeid]
</span></strong></pre>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-1348" src="http://techyaz.com/wp-content/uploads/2017/12/4-Example-Inner-Join.png" alt="inner join example" width="806" height="214" srcset="https://techyaz.com/wp-content/uploads/2017/12/4-Example-Inner-Join.png 806w, https://techyaz.com/wp-content/uploads/2017/12/4-Example-Inner-Join-300x80.png 300w, https://techyaz.com/wp-content/uploads/2017/12/4-Example-Inner-Join-768x204.png 768w" sizes="auto, (max-width: 806px) 100vw, 806px" /></p>
<p><span style="color: #333399;"><strong>Right Join</strong></span></p>
<p>When we use Right Join keyword, it will return all rows from table 2 that is placed right side of <em>RIGHT JOIN</em> keyword and matched rows from table 1 that is mentioned just left to the <em>RIGHT JOIN</em> keyword in SQL statement. In right join, if rows do not match with table 1 it will return <strong>null</strong> value. Sometimes, we call it as Right Outer Join as well. The visual diagram of Right Join is given below.</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-1349" src="http://techyaz.com/wp-content/uploads/2017/12/6-Right-Join.png" alt="right join" width="217" height="145" /></p>
<p><strong>Example</strong></p>
<p>We can see Employees table is mentioned as table 2 and placed just right after keyword <em>RIGHT JOIN</em> and Leavesdetails table has been mentioned as table 1 that is just left to the keyword <em>RIGHT JOIN</em>.</p>
<pre><span style="color: #0000ff;"><strong>SELECT * FROM Leavesdetails
<em>RIGHT JOIN</em> Employees
ON [Employees].[Employeeid]=[Leavesdetails].[Employeeid]
</strong></span></pre>
<p>You can see all values have been displayed from table Employees  along with corresponding details from table 2 Leavesdetails whereas there is one null value row from table Leavesdetails because there is no matched entry for this row from Employees table.</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-1350" src="http://techyaz.com/wp-content/uploads/2017/12/5-Example-Right-Join.png" alt="Right Join Example" width="725" height="226" srcset="https://techyaz.com/wp-content/uploads/2017/12/5-Example-Right-Join.png 725w, https://techyaz.com/wp-content/uploads/2017/12/5-Example-Right-Join-300x94.png 300w" sizes="auto, (max-width: 725px) 100vw, 725px" /></p>
<h5><span style="color: #333399;"><strong>Left Join</strong></span></h5>
<p>When we use <em>LEFT JOIN</em> keyword, it will return all rows from table 1 that is placed just before or left side to the <em>LEFT JOIN</em> keyword and matched rows from table 2 that is mentioned just right side to the <em>LEFT JOIN</em> keyword in SQL statement. In left join, if rows do not match with table 2 it will return <strong>null</strong> value. Left Join is also known as left outer join. You can see the visual representation of Left Join in below image.</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-1351" src="http://techyaz.com/wp-content/uploads/2017/12/8-Left-Join.png" alt="left join" width="242" height="146" /></p>
<p><strong>Example</strong></p>
<p>you can see, now Employee table is mentioned left side of <em>LEFT JOIN</em> keyword and Leavesdetails table is mentioned in right side of this keyword so Employee table will work as table 1 and Leavesdetails will work as table 2.</p>
<pre><span style="color: #0000ff;"><strong>SELECT *
FROM Employees
<em>LEFT JOIN</em> Leavesdetails
ON [Leavesdetails].[Employeeid]=[Employees].[Employeeid]
</strong></span></pre>
<p>We can see all records from Employees table along with its corresponding details from table 2 Leavesdetails whereas one null values from table2 that is Leavesdetails because it&#8217;s matching with the data presented in table 1 Employees table. As highlighted record does not exist in table 2 it is showing null value.</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-1352" src="http://techyaz.com/wp-content/uploads/2017/12/7-Example-Left-Join.png" alt="Left Join Example" width="721" height="221" srcset="https://techyaz.com/wp-content/uploads/2017/12/7-Example-Left-Join.png 721w, https://techyaz.com/wp-content/uploads/2017/12/7-Example-Left-Join-300x92.png 300w" sizes="auto, (max-width: 721px) 100vw, 721px" /></p>
<h5><span style="color: #333399;"><strong>Full Join</strong></span></h5>
<p>When we use <em>FULL JOIN</em>, it fetches results from both tables when there is a match in either in left or right table. We can also say it is kind of combination of left and right join.</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-1353" src="http://techyaz.com/wp-content/uploads/2017/12/10-Full-Join.png" alt="full join" width="235" height="151" /></p>
<p><strong>Example</strong></p>
<p>As visual representation shows, it will show all records from Employees table and Leavesdetails table. You can see in below result set Employee Manvendra has not any leaves detail and same way Employee ID 108 has not any record in Employees table but both rows are showing their values.</p>
<pre><strong><span style="color: #0000ff;">SELECT *
FROM EMPLOYEES
<em>FULL JOIN</em> [dbo].[Leavesdetails] on [Leavesdetails].[Employeeid]=[Employees].[Employeeid]
</span></strong></pre>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-1354" src="http://techyaz.com/wp-content/uploads/2017/12/9-Full-Join.png" alt="full join example" width="779" height="231" srcset="https://techyaz.com/wp-content/uploads/2017/12/9-Full-Join.png 779w, https://techyaz.com/wp-content/uploads/2017/12/9-Full-Join-300x89.png 300w, https://techyaz.com/wp-content/uploads/2017/12/9-Full-Join-768x228.png 768w" sizes="auto, (max-width: 779px) 100vw, 779px" /><br />
I hope you like this article. Please follow our <a href="https://www.facebook.com/Techyaz/">Facebook</a> page and <a href="https://twitter.com/Tech_yaz">Twitter </a>handle to get latest updates.</p>
<p>The post <a href="https://techyaz.com/sql-server/t-sql/understanding-different-types-sql-joins-examples/">Understanding Different Types of SQL JOINs with Examples</a> appeared first on <a href="https://techyaz.com">Techyaz.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://techyaz.com/sql-server/t-sql/understanding-different-types-sql-joins-examples/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Difference between UNION and UNION ALL T-SQL Operators</title>
		<link>https://techyaz.com/sql-server/t-sql/difference-between-union-and-union-all-operators/</link>
					<comments>https://techyaz.com/sql-server/t-sql/difference-between-union-and-union-all-operators/#respond</comments>
		
		<dc:creator><![CDATA[Manvendra Deo Singh]]></dc:creator>
		<pubDate>Wed, 29 Nov 2017 09:55:36 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[T-SQL Operators]]></category>
		<category><![CDATA[union]]></category>
		<guid isPermaLink="false">http://techyaz.com/?p=1269</guid>

					<description><![CDATA[<p>If you want to combine output from multiple tables or queries into one result set, you can do this using an operator known as UNION. A UNION is used to extract rows based on some conditions specified whereas UNION ALL&#46;&#46;&#46;</p>
<p>The post <a href="https://techyaz.com/sql-server/t-sql/difference-between-union-and-union-all-operators/">Difference between UNION and UNION ALL T-SQL Operators</a> appeared first on <a href="https://techyaz.com">Techyaz.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>If you want to combine output from multiple tables or queries into one result set, you can do this using an operator known as UNION. A UNION is used to extract rows based on some conditions specified whereas UNION ALL will extract all rows from both tables. Here, i will discuss difference between UNION and UNION ALL operators ( UNION vs UNION ALL ) in this article along with their use cases.</p>
<h3><span style="color: #333399;">UNION</span></h3>
<p>The UNION operator allows us to combine the results of two or more SELECT statements into a single result set and removes duplicate rows from that result set. Basically, it is performing a DISTINCT operation across all columns in the result set. The UNION operator is different from using joins that combine columns from two tables.</p>
<p>The following are basic rules for combining the result sets of two queries by using UNION:</p>
<ul>
<li>The number and the order of the columns must be the same in all queries.</li>
<li>The data types must be compatible.</li>
<li>Corresponding result set columns in the individual statements that are being combined with UNION must occur in the same order, because UNION compares the columns one-to-one in the order given in the individual queries.</li>
<li>The column names in the result from UNION are taken from the first individual query in the UNION statement.</li>
</ul>
<p>Below example shows how can you use UNION to combine multiple outputs into one result set.</p>
<pre><strong><span style="color: #0000ff;">SELECT * FROM Table1
<span style="color: #008000;">UNION</span>
SELECT * FROM Table2
<span style="color: #008000;">UNION</span>
SELECT * FROM Table3
</span></strong></pre>
<p>If tables would not have same structure or same data types, you will get below error while using UNION:</p>
<p><img loading="lazy" decoding="async" class="aligncenter wp-image-1272 size-full" src="http://techyaz.com/wp-content/uploads/2017/11/Union-Error.jpg" alt="error 205" width="799" height="157" srcset="https://techyaz.com/wp-content/uploads/2017/11/Union-Error.jpg 799w, https://techyaz.com/wp-content/uploads/2017/11/Union-Error-300x59.jpg 300w, https://techyaz.com/wp-content/uploads/2017/11/Union-Error-768x151.jpg 768w" sizes="auto, (max-width: 799px) 100vw, 799px" /></p>
<div>
<p><em><span style="color: #ff0000;">Msg 205, Level 16, State 1, Line 1</span></em><br />
<em><span style="color: #ff0000;"> All queries combined using a UNION, INTERSECT or EXCEPT operator must have an equal number of expressions in their target lists.</span></em></p>
</div>
<h3><span style="color: #333399;">UNION ALL</span></h3>
<p>UNION ALL operator also works like UNION operator that is used to combine multiple result sets into one result set but duplicate rows will not be removed from the result set using UNION ALL unlike the result set of UNION operator that gives distinct rows.</p>
<pre><span style="color: #0000ff;"><strong>SELECT * FROM Table1
<span style="color: #008000;">UNION ALL</span>
SELECT * FROM Table2
<span style="color: #008000;">UNION ALL</span>
SELECT * FROM Table3
</strong></span></pre>
<h3><span style="color: #333399;">Difference Between UNION and UNION ALL ( UNION vs UNION ALL )</span></h3>
<p>Please find important points if we compare the difference between UNION vs UNION ALL result sets and their uses.</p>
<ul>
<li>The UNION operator removes duplicate rows from the result set and gives us distinct rows whereas UNION ALL operator does not remove duplicate rows and give all outputs in the result set.</li>
<li>UNION ALL operator works faster than UNION operator because it does not remove duplicate rows. UNION operator performs distinct sort to remove duplicate rows so its performance is little slower than UNION ALL.</li>
<li>Operator UNION ALL works with all data type columns whereas UNION operator does not work with a column that has a TEXT data type and it will throw error during execution.</li>
</ul>
<h3><span style="color: #333399;">Guidelines to use UNION  and UNION ALL</span></h3>
<p>I have discussed difference between UNION and UNION ALL in above section. Here i will explain below guidelines you should consider while using UNION and UNION ALL operators with other T-SQL statements. Below rules are also apply to EXCEPT and INTERSECT operator:</p>
<ul>
<li>The first query can contain an INTO clause that creates a table to hold the final result set. Only the first query can use an INTO clause. If the INTO clause appears anywhere else, SQL Server displays an error message.</li>
<li>ORDER BY is allowed only at the end of the statement. It cannot be used within the individual queries that make up the statement.</li>
<li>GROUP BY and HAVING clauses can be used only within individual queries; they cannot be used to affect the final result set.</li>
<li>UNION, EXCEPT and INTERSECT can be used within an INSERT statement.</li>
<li>The FOR BROWSE clause cannot be used in statements that involve the UNION, EXCEPT and INTERSECT operators.</li>
</ul>
<p><em><span style="color: #800000;"><strong>Related Articles:</strong></span></em></p>
<ul>
<li><strong><a href="https://techyaz.com/sql-server/how-to-protect-my-stored-procedure-code/" target="_blank" rel="noopener">How to Protect Stored Procedure Code?</a></strong></li>
<li><strong><a href="https://techyaz.com/sql-server/create-logon-trigger-restrict-sysadmin-logins-connect-sql-server-given-time-interval/" target="_blank" rel="noopener">Create a Logon Trigger to Restrict sysadmin logins to Connect to SQL Server during a given time Interval</a></strong></li>
<li><strong><a href="https://techyaz.com/sql-server/get-row-counts-tables-database/" target="_blank" rel="noopener">How to get Total Row Count of all tables of a database</a></strong></li>
</ul>
<p>I hope you like this article. Please follow our <a href="https://www.facebook.com/Techyaz/">Facebook</a> page and <a href="https://twitter.com/Tech_yaz">Twitter </a>handle to get latest updates.</p>
<p>The post <a href="https://techyaz.com/sql-server/t-sql/difference-between-union-and-union-all-operators/">Difference between UNION and UNION ALL T-SQL Operators</a> appeared first on <a href="https://techyaz.com">Techyaz.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://techyaz.com/sql-server/t-sql/difference-between-union-and-union-all-operators/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Understanding Backup Preferences for AlwaysOn Availability Group Databases</title>
		<link>https://techyaz.com/sql-server/alwayson/understanding-sql-server-backup-databases-availability-group/</link>
					<comments>https://techyaz.com/sql-server/alwayson/understanding-sql-server-backup-databases-availability-group/#respond</comments>
		
		<dc:creator><![CDATA[Manvendra Deo Singh]]></dc:creator>
		<pubDate>Thu, 21 Sep 2017 06:53:07 +0000</pubDate>
				<category><![CDATA[AlwaysOn]]></category>
		<category><![CDATA[Backup & Recovery]]></category>
		<category><![CDATA[SQL Server Administration]]></category>
		<category><![CDATA[AOAG]]></category>
		<category><![CDATA[availability group]]></category>
		<category><![CDATA[Backups]]></category>
		<category><![CDATA[HADR]]></category>
		<category><![CDATA[HowTO]]></category>
		<category><![CDATA[T-SQL]]></category>
		<guid isPermaLink="false">http://techyaz.com/?p=943</guid>

					<description><![CDATA[<p>We know SQL Server Backups are resource intensive operation that strain on I/O and CPU (with backup compression). AlwaysOn Availability Group has very good capability to offload SQL Server backups and read operations from primary replica to reduce such workloads&#46;&#46;&#46;</p>
<p>The post <a href="https://techyaz.com/sql-server/alwayson/understanding-sql-server-backup-databases-availability-group/">Understanding Backup Preferences for AlwaysOn Availability Group Databases</a> appeared first on <a href="https://techyaz.com">Techyaz.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>We know <a href="https://techyaz.com/sql-server/understanding-sql-server-backups/" target="_blank" rel="noopener">SQL Server Backups</a> are resource intensive operation that strain on I/O and CPU (with backup compression). <a href="https://techyaz.com/sql-server/alwayson-availability-group/" target="_blank" rel="noopener">AlwaysOn Availability Group</a> has very good capability to offload SQL Server backups and read operations from primary replica to reduce such workloads and utilize secondary replicas in a better way. Read this article to understand backup preferences for AOAG databases.</p>
<p>Before going ahead, we need to understand the rules/points that are very important in order to decide the backup preferences in AOAG configuration. Below are the important points you should consider during designing backup strategy of availability databases.</p>
<ul>
<li>Regular <strong>Full Backups</strong> are not allowed from secondary replicas. Only <a href="https://techyaz.com/sql-server/understanding-sql-server-backups/" target="_blank" rel="noopener">COPY_ONLY full backups</a> are allowed on secondary replicas. That means you cannot run regular Full backup from any of the secondary replica. Remember that copy-only backups do not impact the log chain or clear the differential bitmap.</li>
<li><strong>Differential backups</strong> are not supported on secondary replicas. If you must run differential backups for your availability databases, you should not choose backup preferences as secondary replicas.</li>
<li>Only regular <strong>Log backups</strong> are supported on secondary replicas. COPY_ONLY log backups are not supported on secondary replicas.</li>
<li>Secondary replica must be in <strong>SYNCHRONIZED </strong>or <strong>SYNCHRONIZING </strong>state to backup a secondary database.</li>
<li>Log backup chain is supported across all replicas regardless of where the log backup is taken (primary or secondary replicas) or the mode of the replication (asynchronous or synchronous).</li>
<li>In a distributed availability group, backups can be performed on secondary replicas in the same availability group as the active primary replica, or on the primary replica of any secondary availability groups.</li>
</ul>
<h5><span style="color: #000080;">How SQL Server Decides Which Replica will execute Backup &#8211; Backup Preferences ?</span></h5>
<p>It’s little complex process to determine where backup jobs should run.  If you are confused about this question, then keep reading to get the answer.</p>
<p>To decide on which replica, you should run your backup job depends on your <strong>Backup Preferences</strong> setting. To address this, configure the availability group to specify which availability replicas where you would prefer backups to be performed.</p>
<p>If you choose backup preferences as <strong>secondary only</strong> then you can create jobs on only secondary replicas or if you choose to run it on <strong>primary replica</strong>, then you can configure it on primary replica only. But if you decided to go with default option that is <strong>preferred secondary</strong> then you should schedule backup jobs on all replicas.  Although, Microsoft suggests to create scripted backup-jobs for every availability database on every server instance that hosts an availability replica that is a candidate for performing backups.</p>
<p>Suppose you have chosen <strong>secondary only</strong> preference and you have 3 secondary replicas then question might arise how database engine will decide that on which replica backup should run. Database engine decides where should run backup based on <strong>preferred backup replica</strong> settings and <strong>backup priority</strong> settings. I have explained about these settings later in this article.</p>
<p>AOAG (AlwaysOn Availability group) has a function named <strong>sys.fn_hadr_backup_is_preferred_replica</strong>  to determine which replica is set as preferred backup replica.  If the out of this function returns 1 it means current instance is the preferred backup replica and backup will run on this instance. If returns 0, it means backup will not run on that replica.  We can use this function in a backup script to determine job should run on which replica, so only one of the scheduled jobs actually proceeds to the backup stage.</p>
<p>In the event of a failover, none of the scripts or jobs needs to be modified. Also, if you reconfigure an availability group to add an availability replica, managing the backup job requires simply copying or scheduling the backup job. If you remove an availability replica, simply delete the backup job from the server instance that hosted that replica. Microsoft has given a sample code logic for this function that can be used to develop backup script.</p>
<pre class="brush: sql; title: ; notranslate" title=""><strong><span style="color: #0000ff;">If sys.fn_hadr_backup_is_preferred_replica( @dbname ) &lt;&gt; 1
BEGIN</span>
<span style="color: #008000;">-- If this is not the preferred replica, exit (probably without error).</span>
<span style="color: #0000ff;">END</span>
<span style="color: #008000;">-- If this is the preferred replica, continue to do the backup.
</span></strong></pre>
<p>If you use the Maintenance Plan Wizard to create a given backup job, the job will automatically include the scripting logic that calls and checks the <strong>sys.fn_hadr_backup_is_preferred_replica</strong> function.</p>
<p>If you want to check the preferred backup replica for any availability database, you can get it by running below command. If the output of this function returns 1 it means current instance is the preferred backup replica and backup will run on this instance. If returns 0, it means backup will not run on that replica.</p>
<pre class="brush: sql; title: ; notranslate" title=""><strong><span style="color: #008000;">--Get the backup preference replica for availability database TechYaz.</span>
<span style="color: #0000ff;">SELECT sys.fn_hadr_backup_is_preferred_replica ('TechYaz');
GO
</span></strong></pre>
<p>I have executed same function on my secondary replica. You can see the output is showing as 1, it means this replica is set to run backups.</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-944" src="http://techyaz.com/wp-content/uploads/2017/09/1-backup-replica.jpg" alt="Get preferred backup replica" width="461" height="172" srcset="https://techyaz.com/wp-content/uploads/2017/09/1-backup-replica.jpg 461w, https://techyaz.com/wp-content/uploads/2017/09/1-backup-replica-300x112.jpg 300w" sizes="auto, (max-width: 461px) 100vw, 461px" /></p>
<h5><span style="color: #000080;">Configure Backup of Availability Databases to Run only from Secondary Replicas using GUI</span></h5>
<ol>
<li>Connect to the server instance that hosts the primary replica, and click the server name to expand the server tree. You would not be able to change Backup Preferences from any secondary replicas. If you open the AOAG name property, you will find all options greyed out.</li>
<li>Expand the <strong>Alwayson High Availability </strong>node and the <strong>Availability Groups</strong></li>
<li>Click the availability group whose backup preferences you want to configure, and select the <strong>Properties.</strong></li>
<li>In the <strong>Availability Group Properties </strong>dialog box, select <strong>Backup Preferences</strong> You can see backup preference is set to <strong>Prefer Secondary</strong>, now we need to change it to <strong>Secondary only </strong>option<strong>.</strong> The details about each type of backup preference is given in the screenshot and AOAG backup preference property window.</li>
</ol>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-946" src="http://techyaz.com/wp-content/uploads/2017/09/3-AOAG-property-from-Primary.jpg" alt="AOAG Property Window" width="705" height="637" srcset="https://techyaz.com/wp-content/uploads/2017/09/3-AOAG-property-from-Primary.jpg 705w, https://techyaz.com/wp-content/uploads/2017/09/3-AOAG-property-from-Primary-300x271.jpg 300w" sizes="auto, (max-width: 705px) 100vw, 705px" /></p>
<ol start="5">
<li>There are 4 backup preferences in AOAG that are given below with their capabilities. Choose any as per your requirements. Now I will add one more replica to this availability group as per our requirement and set backup preference to secondary only so that backups always run from either of the both secondary replicas. It is not mandatory for you to add additional replica.</li>
</ol>
<p>
<table id="tablepress-3" class="tablepress tablepress-id-3">
<thead>
<tr class="row-1">
	<th class="column-1">Backup Preference</th><th class="column-2">Backup Runs on</th><th class="column-3">Remarks</th>
</tr>
</thead>
<tbody class="row-striping row-hover">
<tr class="row-2">
	<td class="column-1">Prefer Secondary</td><td class="column-2">Secondary Replica</td><td class="column-3">Default Option. You cannot run differential backup in this option. If only Primary Replica is online, backup will run on Primary Replica.</td>
</tr>
<tr class="row-3">
	<td class="column-1">Secondary only</td><td class="column-2">Only Secondary Replicas</td><td class="column-3">Backup will never run on Primary Replica. If only Primary Replica is online, backup will not run. You cannot run differential backup in this option as well.</td>
</tr>
<tr class="row-4">
	<td class="column-1">Primary</td><td class="column-2">Primary Replica</td><td class="column-3">Choose this option if you want to run differential backup.</td>
</tr>
<tr class="row-5">
	<td class="column-1">Any Replica</td><td class="column-2">Can run on any replica based on backup priority of each availability replica in combination with its operational state and connected state.</td><td class="column-3">Set backup priority carefully between replicas.</td>
</tr>
</tbody>
</table>
</p>
<ol start="6">
<li>Use the <strong>Replica backup priorities</strong> grid to change the <strong>backup priority</strong> of the availability replicas. <strong>Backup Priority</strong> (Lowest=1, Highest=100) specifies your priority for performing backups on this replica relative to the other replicas in the same availability group. In my case backup will run on the replica that has priority 60% and if this will not be available then backup will run on the replica that has priority of 50%. Backup will never run on primary replica irrespective of backup priority settings because we have chosen to run backups only on secondary replica.<br />
<img loading="lazy" decoding="async" class="aligncenter size-full wp-image-947" src="http://techyaz.com/wp-content/uploads/2017/09/4-AOAG-property-from-Primary.jpg" alt="Availability group property Window" width="701" height="635" srcset="https://techyaz.com/wp-content/uploads/2017/09/4-AOAG-property-from-Primary.jpg 701w, https://techyaz.com/wp-content/uploads/2017/09/4-AOAG-property-from-Primary-300x272.jpg 300w" sizes="auto, (max-width: 701px) 100vw, 701px" /><br />
We have also an option Exclude Replica to exclude any replica where you don’t want to run backups. This is useful for remote availability replicas to which you never want to run backups there.<br />
You should click on checkbox for your respective replica name for which you want to exclude the backup as shown in above screenshot.</li>
</ol>
<ol start="7">
<li>Click on OK button to apply the changes.</li>
</ol>
<h5><span style="color: #000080;">Configure SQL Server Backup in AOAG to Run with default backup preference using T-SQL</span></h5>
<p>I have shown you how to change backup preference setting to run backups from secondary replicas using GUI. We can do the same using T-SQL commands as well. Here i will show you how to change backup preference using T-SQL. As we have changed the backup preference to secondary only option where backups will never run from primary replica. Now we can revert this change to default option using T-SQL. <strong>Prefer Secondary</strong> is default option in which backups run from secondary replica and if only primary replica is online then it will run from primary replica only.</p>
<p>Connect to the server instance that hosts the primary replica and run below command.</p>
<pre class="brush: sql; title: ; notranslate" title=""><strong><span style="color: #008000;">--Choose backup preference as per your choice and pass that value in AUTOMATED_BACKUP_PREFERENCE = { PRIMARY | SECONDARY_ONLY| SECONDARY | NONE }</span>
<span style="color: #0000ff;">ALTER AVAILABILITY GROUP AG_AOAGName SET (AUTOMATED_BACKUP_PREFERENCE = SECONDARY)
GO
</span></strong></pre>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-948" src="http://techyaz.com/wp-content/uploads/2017/09/5-t-sql.jpg" alt="Change backup preference using T-sql" width="606" height="151" srcset="https://techyaz.com/wp-content/uploads/2017/09/5-t-sql.jpg 606w, https://techyaz.com/wp-content/uploads/2017/09/5-t-sql-300x75.jpg 300w" sizes="auto, (max-width: 606px) 100vw, 606px" /></p>
<p>Now your backup preference would be set to <strong>Prefer Secondary</strong> and backups will run from primary replica if only primary replica will be online.</p>
<p><em><span style="color: #800000;"><strong>Related Articles:</strong></span></em></p>
<ul>
<li><span style="color: #0000ff;"><strong><a style="color: #0000ff;" href="https://techyaz.com/sql-server/troubleshooting/secondary-replica-not-coming-online-showing-resolving-state-automatic-failover-alwayson-availability-group-configuration/" target="_blank" rel="noopener">Fix: Secondary Replica Stucked in to Resolving state</a></strong></span></li>
<li><span style="color: #0000ff;"><strong><a style="color: #0000ff;" href="https://techyaz.com/sql-server/troubleshooting/fixing-sap-connectivity-issue-aoag-automatic-failover/" target="_blank" rel="noopener">Fix: Connectivity Issue after AOAG Automatic Failover</a></strong></span></li>
<li><span style="color: #0000ff;"><strong><a style="color: #0000ff;" href="https://techyaz.com/sql-server/understanding-sql-server-recovery-model/" target="_blank" rel="noopener">Understanding SQL Server Recovery Models</a></strong></span></li>
<li><span style="color: #0000ff;"><strong><a style="color: #0000ff;" href="https://techyaz.com/sql-server/troubleshooting/fix-error-19471-listener-issue-that-came-during-configuring-sql-server-alwayson-availability-group/" target="_blank" rel="noopener">Fix: Listener Issue Error 19471</a></strong></span></li>
</ul>
<p>I hope you like this article. Please follow us on our <a href="https://www.facebook.com/Techyaz/">facebook page</a> and on <a href="https://twitter.com/Tech_yaz">Twitter </a>handle to get latest updates.</p>
<p>The post <a href="https://techyaz.com/sql-server/alwayson/understanding-sql-server-backup-databases-availability-group/">Understanding Backup Preferences for AlwaysOn Availability Group Databases</a> appeared first on <a href="https://techyaz.com">Techyaz.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://techyaz.com/sql-server/alwayson/understanding-sql-server-backup-databases-availability-group/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How to Disable AutoCommit in SQL Server?</title>
		<link>https://techyaz.com/sql-server/t-sql/how-to-disable-auto-commit-in-sql-server/</link>
					<comments>https://techyaz.com/sql-server/t-sql/how-to-disable-auto-commit-in-sql-server/#respond</comments>
		
		<dc:creator><![CDATA[Manvendra Deo Singh]]></dc:creator>
		<pubDate>Wed, 09 Feb 2011 11:25:00 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[T-SQL]]></category>
		<category><![CDATA[HowTO]]></category>
		<guid isPermaLink="false">http://techyaz.com/sql-server/t-sql-codes/how-to-disable-auto-commit-in-sql-server/</guid>

					<description><![CDATA[<p>Autocommit mode is the default transaction management mode of the SQL Server Database Engine. Every Transact-SQL statement is committed or rolled back when it completes. If a statement completes successfully, it is committed; if it encounters any error, it is&#46;&#46;&#46;</p>
<p>The post <a href="https://techyaz.com/sql-server/t-sql/how-to-disable-auto-commit-in-sql-server/">How to Disable AutoCommit in SQL Server?</a> appeared first on <a href="https://techyaz.com">Techyaz.com</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Autocommit mode is the default transaction management mode of the SQL Server Database Engine. Every Transact-SQL statement is committed or rolled back when it completes. If a statement completes successfully, it is committed; if it encounters any error, it is rolled back.</p>
<h3><span style="color: #333399;">Enable or Disable Autocommit using T-SQL</span></h3>
<p>You can turn off auto commit by setting implicit_transactions ON. Run below T-SQL command to turn off autocommit in SQL Server.</p>
<pre><strong><span style="color: #0000ff;">SET IMPLICIT_TRANSACTIONS ON</span></strong></pre>
<p>When the setting is ON, it returns to implicit transaction mode. In implicit transaction mode, every change you make starts a transactions which you have to commit manually. When you need to enable it just run above command with OFF clause. Run below command to enable auto commit.</p>
<pre><span style="color: #0000ff;"><strong>SET IMPLICIT_TRANSACTIONS OFF</strong></span></pre>
<p>autocommit is the default for Sql Server 2000 onwards.</p>
<h3><span style="color: #333399;">Enable or Disable Autocommit using GUI</span></h3>
<p>You can also turn off autocommit using SQL Server Management Studio by following below steps.</p>
<ol>
<li>Connect to SQL Server Instance in SQL Server Management Studio.</li>
<li>From the Menu bar, click on <strong>Tools</strong> and then choose <strong>Options</strong></li>
<li>Select <strong>Query Execution</strong> then <strong>SQL Server</strong> followed by <strong>ANSI</strong></li>
<li>Make sure to click on check box <strong>SET IMPLICIT_TRANSACTIONS</strong></li>
<li>Click on<strong> OK</strong></li>
</ol>
<p>Now, open a new Query window and start executing the scripts. If you want to turn it on the follow same steps as given above and uncheck the <strong>SET IMPLICIT_TRANSACTIONS </strong>option that are mentioned in step no 4.</p>
<p><span style="color: #800000;"><strong>Related Articles:</strong></span></p>
<ul>
<li><strong><a href="https://techyaz.com/sql-server/get-row-counts-tables-database/" target="_blank" rel="noopener">How to get Total Row Count of all tables of a database?</a></strong></li>
<li><strong><a href="https://techyaz.com/sql-server/how-to-avoid-page-split-in-sql-server/" target="_blank" rel="noopener">Understanding Page Split in SQL Server</a></strong></li>
<li><strong><a href="https://techyaz.com/sql-server/what-should-be-the-best-value-for-fill-factor-in-sql-server/" target="_blank" rel="noopener">What should be the Best Value for Fill Factor?</a></strong></li>
<li><strong><a href="https://techyaz.com/sql-server/sql-server-on-linux/21-missing-features-in-sql-server-on-linux/" target="_blank" rel="noopener">Top 21 New Features in SQL Server 2017 that is missing from SQL Server on Linux</a></strong></li>
<li><strong><a href="https://techyaz.com/sql-server/always-turn-off-database-auto-shrink/" target="_blank" rel="noopener">Read Why We should always Turn Off Database AutoShrink Database Property</a></strong></li>
</ul>
<p>I hope you like this tip. You can drop your questions and feedbacks in comment sections. Also you can follow our <strong><a href="https://www.facebook.com/Techyaz/">facebook</a></strong> page and <strong><a href="https://twitter.com/Tech_yaz">Twitter</a></strong> handle to get latest updates.</p>
<p>The post <a href="https://techyaz.com/sql-server/t-sql/how-to-disable-auto-commit-in-sql-server/">How to Disable AutoCommit in SQL Server?</a> appeared first on <a href="https://techyaz.com">Techyaz.com</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://techyaz.com/sql-server/t-sql/how-to-disable-auto-commit-in-sql-server/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
