<?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>SQL Server Error &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/sql-server-error/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.dbrnd.com</link>
	<description>BIGData &#124; NoSQL &#124; MSSQL &#124; MySQL &#124; PostgreSQL</description>
	<lastBuildDate>Mon, 24 Jun 2019 19:39:08 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.4</generator>
	<item>
		<title>SQL Server: Script to check Network or Connect permission of User</title>
		<link>https://www.dbrnd.com/2019/06/sql-server-script-to-check-network-or-connect-permission-of-user/</link>
					<comments>https://www.dbrnd.com/2019/06/sql-server-script-to-check-network-or-connect-permission-of-user/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 24 Jun 2019 16:16:20 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server DBA Script]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[endpoints]]></category>
		<category><![CDATA[server_permissions]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Error]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tuning]]></category>
		<category><![CDATA[SQL Server Programming]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=7263</guid>

					<description><![CDATA[In this post, I am sharing a script for checking the Network and Connect related permission of SQL Server User. When you installed the SQL Server, for network access you should enable the TCP/IP pipeline and other connect permission so that others can access the server. Using below script, you can easily identify those permissions [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F06%2Fsql-server-script-to-check-network-or-connect-permission-of-user%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20check%20Network%20or%20Connect%20permission%20of%20User" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F06%2Fsql-server-script-to-check-network-or-connect-permission-of-user%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20check%20Network%20or%20Connect%20permission%20of%20User" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F06%2Fsql-server-script-to-check-network-or-connect-permission-of-user%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20check%20Network%20or%20Connect%20permission%20of%20User" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F06%2Fsql-server-script-to-check-network-or-connect-permission-of-user%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20check%20Network%20or%20Connect%20permission%20of%20User" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F06%2Fsql-server-script-to-check-network-or-connect-permission-of-user%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20check%20Network%20or%20Connect%20permission%20of%20User" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F06%2Fsql-server-script-to-check-network-or-connect-permission-of-user%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20check%20Network%20or%20Connect%20permission%20of%20User" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F06%2Fsql-server-script-to-check-network-or-connect-permission-of-user%2F&#038;title=SQL%20Server%3A%20Script%20to%20check%20Network%20or%20Connect%20permission%20of%20User" data-a2a-url="https://www.dbrnd.com/2019/06/sql-server-script-to-check-network-or-connect-permission-of-user/" data-a2a-title="SQL Server: Script to check Network or Connect permission of User"></a></p><p>In this post, I am sharing a script for checking the Network and Connect related permission of SQL Server User. </p>
<p>When you installed the SQL Server, for network access you should enable the TCP/IP pipeline and other connect permission so that others can access the server. </p>
<p>Using below script, you can easily identify those permissions which are important for connecting SQL Server. I took the reference from <a href="https://docs.microsoft.com/en-us/sql/database-engine/availability-groups/windows/troubleshoot-always-on-availability-groups-configuration-sql-server" rel="noopener" target="_blank">this</a> official page. </p>
<pre class="crayon-plain-tag">SELECT 
	EP.name, 
	SP.STATE,   
	CONVERT(nvarchar(38), suser_name(SP.grantor_principal_id)) AS GRANTOR,   
	SP.TYPE AS PERMISSION,  
	CONVERT(nvarchar(46),suser_name(SP.grantee_principal_id)) AS GRANTEE   
FROM sys.server_permissions SP, sys.endpoints EP  
WHERE SP.major_id = EP.endpoint_id  
ORDER BY Permission,grantor, grantee</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2019/06/sql-server-script-to-check-network-or-connect-permission-of-user/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>SQL Server Interview: How to remove New Line Character from a string?</title>
		<link>https://www.dbrnd.com/2019/04/sql-server-interview-how-to-remove-new-line-character-from-a-string/</link>
					<comments>https://www.dbrnd.com/2019/04/sql-server-interview-how-to-remove-new-line-character-from-a-string/#respond</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 29 Apr 2019 16:16:57 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server Interview]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[Remove New Line character]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Error]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tuning]]></category>
		<category><![CDATA[SQL Server Programming]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[String Operation]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=7413</guid>

					<description><![CDATA[In this post, I am sharing a SQL Interview questions for Database Developer. If you are database fresher and working with SQL, you must prepare for string/date operations related questions and answers. One of the example questions is How to remove New Line Character from a string? Check the below sample code: [crayon-6a95ba227b8fb879061104/]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F04%2Fsql-server-interview-how-to-remove-new-line-character-from-a-string%2F&amp;linkname=SQL%20Server%20Interview%3A%20How%20to%20remove%20New%20Line%20Character%20from%20a%20string%3F" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F04%2Fsql-server-interview-how-to-remove-new-line-character-from-a-string%2F&amp;linkname=SQL%20Server%20Interview%3A%20How%20to%20remove%20New%20Line%20Character%20from%20a%20string%3F" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F04%2Fsql-server-interview-how-to-remove-new-line-character-from-a-string%2F&amp;linkname=SQL%20Server%20Interview%3A%20How%20to%20remove%20New%20Line%20Character%20from%20a%20string%3F" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F04%2Fsql-server-interview-how-to-remove-new-line-character-from-a-string%2F&amp;linkname=SQL%20Server%20Interview%3A%20How%20to%20remove%20New%20Line%20Character%20from%20a%20string%3F" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F04%2Fsql-server-interview-how-to-remove-new-line-character-from-a-string%2F&amp;linkname=SQL%20Server%20Interview%3A%20How%20to%20remove%20New%20Line%20Character%20from%20a%20string%3F" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F04%2Fsql-server-interview-how-to-remove-new-line-character-from-a-string%2F&amp;linkname=SQL%20Server%20Interview%3A%20How%20to%20remove%20New%20Line%20Character%20from%20a%20string%3F" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F04%2Fsql-server-interview-how-to-remove-new-line-character-from-a-string%2F&#038;title=SQL%20Server%20Interview%3A%20How%20to%20remove%20New%20Line%20Character%20from%20a%20string%3F" data-a2a-url="https://www.dbrnd.com/2019/04/sql-server-interview-how-to-remove-new-line-character-from-a-string/" data-a2a-title="SQL Server Interview: How to remove New Line Character from a string?"></a></p><p>In this post, I am sharing a SQL Interview questions for Database Developer. If you are database fresher and working with SQL, you must prepare for string/date operations related questions and answers. </p>
<p>One of the example questions is How to remove New Line Character from a string?</p>
<p><strong>Check the below sample code:</strong></p><pre class="crayon-plain-tag">DECLARE @str VARCHAR(100)
SET @str = 'I am Database 
Engineer'

SELECT @str AS With_New_Line

With_New_Line
---------------------
I am Database 
Engineer

SELECT REPLACE(REPLACE(@str, CHAR(13), ''), CHAR(10), '') AS Without_New_Line

Without_New_Line
---------------------------
I am Database Engineer</pre><p> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2019/04/sql-server-interview-how-to-remove-new-line-character-from-a-string/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>SQL Server: Set IDENTITY to existing Column of a Table</title>
		<link>https://www.dbrnd.com/2019/01/sql-server-set-identity-to-existing-column-of-a-table/</link>
					<comments>https://www.dbrnd.com/2019/01/sql-server-set-identity-to-existing-column-of-a-table/#respond</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 07 Jan 2019 16:16:24 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[ALTER COLUMN]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[Identity Column]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Error]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tuning]]></category>
		<category><![CDATA[SQL Server Programming]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=7389</guid>

					<description><![CDATA[Last week, I was exploring few SQL Server forums and found an interesting discussion on the IDENTITY Column of SQL Server. One of the discussions like How to set IDENTITY to existing column of a Table? Actually, there is no any specific option for setting IDENTITY to existing Column of a Table. But there are [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F01%2Fsql-server-set-identity-to-existing-column-of-a-table%2F&amp;linkname=SQL%20Server%3A%20Set%20IDENTITY%20to%20existing%20Column%20of%20a%20Table" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F01%2Fsql-server-set-identity-to-existing-column-of-a-table%2F&amp;linkname=SQL%20Server%3A%20Set%20IDENTITY%20to%20existing%20Column%20of%20a%20Table" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F01%2Fsql-server-set-identity-to-existing-column-of-a-table%2F&amp;linkname=SQL%20Server%3A%20Set%20IDENTITY%20to%20existing%20Column%20of%20a%20Table" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F01%2Fsql-server-set-identity-to-existing-column-of-a-table%2F&amp;linkname=SQL%20Server%3A%20Set%20IDENTITY%20to%20existing%20Column%20of%20a%20Table" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F01%2Fsql-server-set-identity-to-existing-column-of-a-table%2F&amp;linkname=SQL%20Server%3A%20Set%20IDENTITY%20to%20existing%20Column%20of%20a%20Table" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F01%2Fsql-server-set-identity-to-existing-column-of-a-table%2F&amp;linkname=SQL%20Server%3A%20Set%20IDENTITY%20to%20existing%20Column%20of%20a%20Table" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F01%2Fsql-server-set-identity-to-existing-column-of-a-table%2F&#038;title=SQL%20Server%3A%20Set%20IDENTITY%20to%20existing%20Column%20of%20a%20Table" data-a2a-url="https://www.dbrnd.com/2019/01/sql-server-set-identity-to-existing-column-of-a-table/" data-a2a-title="SQL Server: Set IDENTITY to existing Column of a Table"></a></p><p>Last week, I was exploring few SQL Server forums and found an interesting discussion on the IDENTITY Column of SQL Server.<br />
One of the discussions like How to set IDENTITY to existing column of a Table?</p>
<p>Actually, there is no any specific option for setting IDENTITY to existing Column of a Table.</p>
<p>But there are different tricks to do this, sharing one of the tricks here&#8230;</p>
<p><strong>Create a sample table without identity column:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE tbl_TestIdentity (ID INT, Name VARCHAR(10))

INSERT INTO tbl_TestIdentity VALUES 
(1,'ABC'), (2,'XYZ'),(3,'PQR')
,(4,'WER'),(5,'JKL'),(6,'ZXC')</pre> </p>
<p><strong>Check the data:</strong></p>
<pre class="crayon-plain-tag">SELECT *from tbl_TestIdentity

ID          Name
----------- ----------
1           ABC
2           XYZ
3           PQR
4           WER
5           JKL
6           ZXC</pre> </p>
<p><strong>Add new IDENTITY Column to table:</strong></p>
<pre class="crayon-plain-tag">ALTER TABLE tbl_TestIdentity ADD ID2 INT IDENTITY (1,1);</pre> </p>
<p><strong>Drop old ID Column:</strong></p>
<pre class="crayon-plain-tag">ALTER TABLE tbl_TestIdentity DROP COLUMN ID</pre> </p>
<p><strong>Rename new column to old column name:</strong></p>
<pre class="crayon-plain-tag">Exec sp_rename 'tbl_TestIdentity.ID2', 'ID', 'Column'</pre> </p>
<p><strong>Result:</strong></p>
<pre class="crayon-plain-tag">SELECT *from tbl_TestIdentity

Name       ID
---------- -----------
ABC        1
XYZ        2
PQR        3
WER        4
JKL        5
ZXC        6</pre> </p>
<blockquote class="wp-embedded-content" data-secret="kDApBclIAZ"><p><a href="https://www.dbrnd.com/2018/03/sql-server-how-to-remove-identity-from-a-column/">SQL Server: How to remove IDENTITY from a Column?</a></p></blockquote>
<p><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2018/03/sql-server-how-to-remove-identity-from-a-column/embed/#?secret=kDApBclIAZ" data-secret="kDApBclIAZ" width="600" height="338" title="&#8220;SQL Server: How to remove IDENTITY from a Column?&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<blockquote class="wp-embedded-content" data-secret="SARIxB3LJX"><p><a href="https://www.dbrnd.com/2015/12/sql-server-script-to-find-identity-column-of-a-database/">SQL Server: Script to find Identity Column of a Database</a></p></blockquote>
<p><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2015/12/sql-server-script-to-find-identity-column-of-a-database/embed/#?secret=SARIxB3LJX" data-secret="SARIxB3LJX" width="600" height="338" title="&#8220;SQL Server: Script to find Identity Column of a Database&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2019/01/sql-server-set-identity-to-existing-column-of-a-table/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>SQL Server: If Table Exists in a Database, don&#8217;t perform any action</title>
		<link>https://www.dbrnd.com/2018/12/sql-server-if-table-exists-in-a-database-dont-perform-any-action/</link>
					<comments>https://www.dbrnd.com/2018/12/sql-server-if-table-exists-in-a-database-dont-perform-any-action/#respond</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 24 Dec 2018 16:16:35 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[Check Table Exists]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[IF Table Exists]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Error]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tuning]]></category>
		<category><![CDATA[SQL Server Programming]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=7387</guid>

					<description><![CDATA[In this post, I am sharing few options for checking whether a table exists in a SQL Server database or not. When you are preparing the full database change script, you should put DDL statements in the IF EXISTS condition for avoiding any error. Option 1: [crayon-6a95ba227bd4b395388606/] Option 2: [crayon-6a95ba227bd4c979329496/] Option 3: [crayon-6a95ba227bd4d286493907/] Option 4: [&#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%2F2018%2F12%2Fsql-server-if-table-exists-in-a-database-dont-perform-any-action%2F&amp;linkname=SQL%20Server%3A%20If%20Table%20Exists%20in%20a%20Database%2C%20don%E2%80%99t%20perform%20any%20action" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F12%2Fsql-server-if-table-exists-in-a-database-dont-perform-any-action%2F&amp;linkname=SQL%20Server%3A%20If%20Table%20Exists%20in%20a%20Database%2C%20don%E2%80%99t%20perform%20any%20action" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F12%2Fsql-server-if-table-exists-in-a-database-dont-perform-any-action%2F&amp;linkname=SQL%20Server%3A%20If%20Table%20Exists%20in%20a%20Database%2C%20don%E2%80%99t%20perform%20any%20action" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F12%2Fsql-server-if-table-exists-in-a-database-dont-perform-any-action%2F&amp;linkname=SQL%20Server%3A%20If%20Table%20Exists%20in%20a%20Database%2C%20don%E2%80%99t%20perform%20any%20action" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F12%2Fsql-server-if-table-exists-in-a-database-dont-perform-any-action%2F&amp;linkname=SQL%20Server%3A%20If%20Table%20Exists%20in%20a%20Database%2C%20don%E2%80%99t%20perform%20any%20action" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F12%2Fsql-server-if-table-exists-in-a-database-dont-perform-any-action%2F&amp;linkname=SQL%20Server%3A%20If%20Table%20Exists%20in%20a%20Database%2C%20don%E2%80%99t%20perform%20any%20action" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F12%2Fsql-server-if-table-exists-in-a-database-dont-perform-any-action%2F&#038;title=SQL%20Server%3A%20If%20Table%20Exists%20in%20a%20Database%2C%20don%E2%80%99t%20perform%20any%20action" data-a2a-url="https://www.dbrnd.com/2018/12/sql-server-if-table-exists-in-a-database-dont-perform-any-action/" data-a2a-title="SQL Server: If Table Exists in a Database, don’t perform any action"></a></p><p>In this post, I am sharing few options for checking whether a table exists in a SQL Server database or not. </p>
<p>When you are preparing the full database change script, you should put DDL statements in the IF EXISTS condition for avoiding any error. </p>
<p><strong>Option 1:</strong></p>
<pre class="crayon-plain-tag">IF OBJECT_ID(N'table_name', N'U') IS NOT NULL
BEGIN
    PRINT 'Table Exists...'
END
ELSE
BEGIN
	PRINT 'Table Does not Exists...'
END</pre> </p>
<p><strong>Option 2:</strong></p>
<pre class="crayon-plain-tag">IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = N'table_name')
BEGIN
    PRINT 'Table Exists...'
END
ELSE
BEGIN
	PRINT 'Table Does not Exists...'
END</pre> </p>
<p><strong>Option 3:</strong></p>
<pre class="crayon-plain-tag">IF EXISTS(SELECT 1 FROM sys.Objects WHERE  Object_id = OBJECT_ID(N'table_name') AND Type = N'U')
BEGIN
   PRINT 'Table Exists...'
END
ELSE
BEGIN
	PRINT 'Table Does not Exists...'
END</pre> </p>
<p><strong>Option 4:</strong></p>
<pre class="crayon-plain-tag">IF EXISTS(SELECT 1 FROM sys.Tables WHERE  Name = N'table_name' AND Type = N'U')
BEGIN
    PRINT 'Table Exists...'
END
ELSE
BEGIN
	PRINT 'Table Does not Exists...'
END</pre> </p>
<p><strong>Option 5:</strong></p>
<pre class="crayon-plain-tag">IF EXISTS(SELECT name FROM sys.sysobjects WHERE Name = N'table_name' AND xtype = N'U')
BEGIN
    PRINT 'Table Exists...'
END
ELSE
BEGIN
	PRINT 'Table Does not Exists...'
END</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2018/12/sql-server-if-table-exists-in-a-database-dont-perform-any-action/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>SQL Server: If a Column Exists in a Table, don&#8217;t add it</title>
		<link>https://www.dbrnd.com/2018/12/sql-server-if-a-column-exists-in-a-table-dont-add-it/</link>
					<comments>https://www.dbrnd.com/2018/12/sql-server-if-a-column-exists-in-a-table-dont-add-it/#respond</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 10 Dec 2018 16:16:50 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[Column Existence]]></category>
		<category><![CDATA[Column Exists]]></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 Error]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tuning]]></category>
		<category><![CDATA[SQL Server Programming]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=7383</guid>

					<description><![CDATA[In this post, I am sharing two options for checking whether a column exists in a SQL Server table or not. When you are preparing the full database change script, you should put DDL statements in the IF EXISTS condition for avoiding any error. Option 1: Check the column existence and add id [crayon-6a95ba227be10600062612/] Option [&#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%2F2018%2F12%2Fsql-server-if-a-column-exists-in-a-table-dont-add-it%2F&amp;linkname=SQL%20Server%3A%20If%20a%20Column%20Exists%20in%20a%20Table%2C%20don%E2%80%99t%20add%20it" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F12%2Fsql-server-if-a-column-exists-in-a-table-dont-add-it%2F&amp;linkname=SQL%20Server%3A%20If%20a%20Column%20Exists%20in%20a%20Table%2C%20don%E2%80%99t%20add%20it" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F12%2Fsql-server-if-a-column-exists-in-a-table-dont-add-it%2F&amp;linkname=SQL%20Server%3A%20If%20a%20Column%20Exists%20in%20a%20Table%2C%20don%E2%80%99t%20add%20it" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F12%2Fsql-server-if-a-column-exists-in-a-table-dont-add-it%2F&amp;linkname=SQL%20Server%3A%20If%20a%20Column%20Exists%20in%20a%20Table%2C%20don%E2%80%99t%20add%20it" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F12%2Fsql-server-if-a-column-exists-in-a-table-dont-add-it%2F&amp;linkname=SQL%20Server%3A%20If%20a%20Column%20Exists%20in%20a%20Table%2C%20don%E2%80%99t%20add%20it" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F12%2Fsql-server-if-a-column-exists-in-a-table-dont-add-it%2F&amp;linkname=SQL%20Server%3A%20If%20a%20Column%20Exists%20in%20a%20Table%2C%20don%E2%80%99t%20add%20it" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F12%2Fsql-server-if-a-column-exists-in-a-table-dont-add-it%2F&#038;title=SQL%20Server%3A%20If%20a%20Column%20Exists%20in%20a%20Table%2C%20don%E2%80%99t%20add%20it" data-a2a-url="https://www.dbrnd.com/2018/12/sql-server-if-a-column-exists-in-a-table-dont-add-it/" data-a2a-title="SQL Server: If a Column Exists in a Table, don’t add it"></a></p><p>In this post, I am sharing two options for checking whether a column exists in a SQL Server table or not.<br />
When you are preparing the full database change script, you should put DDL statements in the IF EXISTS condition for avoiding any error. </p>
<p><strong>Option 1: Check the column existence and add id</strong></p>
<pre class="crayon-plain-tag">if not exists 
(
	select column_name 
	from INFORMATION_SCHEMA.columns 
	where table_name = 'table_name'
		and column_name = 'new_column_name'
)

ALTER TABLE table_name add new_column_name TEXT</pre> </p>
<p><strong>Option 2: Check the column existance</strong></p>
<pre class="crayon-plain-tag">IF COL_LENGTH('table_name','column_name') IS NULL
BEGIN
 /*Write your code...*/
END</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2018/12/sql-server-if-a-column-exists-in-a-table-dont-add-it/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>SQL Server: Script to find the Largest Object of a Database</title>
		<link>https://www.dbrnd.com/2018/11/sql-server-script-to-find-the-largest-object-of-a-database/</link>
					<comments>https://www.dbrnd.com/2018/11/sql-server-script-to-find-the-largest-object-of-a-database/#respond</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 26 Nov 2018 16:16:09 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server DBA Script]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[database size]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[log size]]></category>
		<category><![CDATA[longest object]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Error]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tuning]]></category>
		<category><![CDATA[SQL Server Programming]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[table size]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=7393</guid>

					<description><![CDATA[In this post, I am sharing a script for finding the largest object of a SQL Server Database. Whenever I find any handy script which we can use in day to day work, I am sharing without fail. When you are doing the database clean up or maintenance activity, you probably need to check the [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F11%2Fsql-server-script-to-find-the-largest-object-of-a-database%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20the%20Largest%20Object%20of%20a%20Database" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F11%2Fsql-server-script-to-find-the-largest-object-of-a-database%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20the%20Largest%20Object%20of%20a%20Database" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F11%2Fsql-server-script-to-find-the-largest-object-of-a-database%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20the%20Largest%20Object%20of%20a%20Database" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F11%2Fsql-server-script-to-find-the-largest-object-of-a-database%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20the%20Largest%20Object%20of%20a%20Database" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F11%2Fsql-server-script-to-find-the-largest-object-of-a-database%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20the%20Largest%20Object%20of%20a%20Database" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F11%2Fsql-server-script-to-find-the-largest-object-of-a-database%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20the%20Largest%20Object%20of%20a%20Database" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F11%2Fsql-server-script-to-find-the-largest-object-of-a-database%2F&#038;title=SQL%20Server%3A%20Script%20to%20find%20the%20Largest%20Object%20of%20a%20Database" data-a2a-url="https://www.dbrnd.com/2018/11/sql-server-script-to-find-the-largest-object-of-a-database/" data-a2a-title="SQL Server: Script to find the Largest Object of a Database"></a></p><p>In this post, I am sharing a script for finding the largest object of a SQL Server Database.<br />
Whenever I find any handy script which we can use in day to day work, I am sharing without fail. </p>
<p>When you are doing the database clean up or maintenance activity, you probably need to check the big size of objects. </p>
<p>I already shared few couples of the script on checking the size of table, database, log files. </p>
<blockquote class="wp-embedded-content" data-secret="IysDiP8zGp"><p><a href="https://www.dbrnd.com/2016/04/sql-server-find-the-total-row-count-and-size-of-the-tables/">SQL Server: Find the total row count and size of the Tables</a></p></blockquote>
<p><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/04/sql-server-find-the-total-row-count-and-size-of-the-tables/embed/#?secret=IysDiP8zGp" data-secret="IysDiP8zGp" width="600" height="338" title="&#8220;SQL Server: Find the total row count and size of the Tables&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<blockquote class="wp-embedded-content" data-secret="PHUFsnDphr"><p><a href="https://www.dbrnd.com/2017/08/sql-server-script-to-check-the-size-of-query-plan-cache-dm_os_memory_clerks/">SQL Server: Script to check the size of Query Plan Cache</a></p></blockquote>
<p><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2017/08/sql-server-script-to-check-the-size-of-query-plan-cache-dm_os_memory_clerks/embed/#?secret=PHUFsnDphr" data-secret="PHUFsnDphr" width="600" height="338" title="&#8220;SQL Server: Script to check the size of Query Plan Cache&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<blockquote class="wp-embedded-content" data-secret="cVZ3A8pmYJ"><p><a href="https://www.dbrnd.com/2015/11/sql-server-script-to-find-the-size-of-database-files-and-log-files/">SQL Server: Script to find the size of Database Files and Log Files</a></p></blockquote>
<p><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2015/11/sql-server-script-to-find-the-size-of-database-files-and-log-files/embed/#?secret=cVZ3A8pmYJ" data-secret="cVZ3A8pmYJ" width="600" height="338" title="&#8220;SQL Server: Script to find the size of Database Files and Log Files&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<p><strong>Here, below script is used for finding the largest object of a database:</strong></p><pre class="crayon-plain-tag">SELECT 
    t.NAME AS TableName
    ,i.name as indexName
    ,sum(p.rows) as RowCounts
    ,sum(a.total_pages) as TotalPages
    ,sum(a.used_pages) as UsedPages
    ,sum(a.data_pages) as DataPages
    ,(sum(a.total_pages) * 8) / 1024 as TotalSpaceMB
    ,(sum(a.used_pages) * 8) / 1024 as UsedSpaceMB 
    ,(sum(a.data_pages) * 8) / 1024 as DataSpaceMB
FROM sys.tables t
INNER JOIN sys.indexes i ON t.OBJECT_ID = i.object_id
INNER JOIN sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id
INNER JOIN sys.allocation_units a ON p.partition_id = a.container_id
WHERE t.NAME NOT LIKE 'dt%' 
	AND i.OBJECT_ID &gt; 255 
	AND i.index_id &lt;= 1
GROUP BY 
    t.NAME, i.object_id, i.index_id, i.name 
ORDER BY SUM(a.total_pages) DESC</pre><p> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2018/11/sql-server-script-to-find-the-largest-object-of-a-database/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>SQL Server: Script to find the Size of Indexes</title>
		<link>https://www.dbrnd.com/2018/11/sql-server-script-to-find-the-size-of-indexes/</link>
					<comments>https://www.dbrnd.com/2018/11/sql-server-script-to-find-the-size-of-indexes/#respond</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 12 Nov 2018 16:16:48 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server DBA Script]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[Big size of Index]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[index fragmentation]]></category>
		<category><![CDATA[index size]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Error]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tuning]]></category>
		<category><![CDATA[SQL Server Programming]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=7391</guid>

					<description><![CDATA[In this post, I am sharing a script for finding the size of Indexes in SQL Server. I also shared different DBA scripts on SQL Server Indexes as Find the fragmentation of Indexes, Indexes Statistics. SQL Server: Script to find Index Average Fragmentation in Percentage SQL Server: Script to find Outdated Index Statistics Using the [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F11%2Fsql-server-script-to-find-the-size-of-indexes%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20the%20Size%20of%20Indexes" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F11%2Fsql-server-script-to-find-the-size-of-indexes%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20the%20Size%20of%20Indexes" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F11%2Fsql-server-script-to-find-the-size-of-indexes%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20the%20Size%20of%20Indexes" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F11%2Fsql-server-script-to-find-the-size-of-indexes%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20the%20Size%20of%20Indexes" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F11%2Fsql-server-script-to-find-the-size-of-indexes%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20the%20Size%20of%20Indexes" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F11%2Fsql-server-script-to-find-the-size-of-indexes%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20the%20Size%20of%20Indexes" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F11%2Fsql-server-script-to-find-the-size-of-indexes%2F&#038;title=SQL%20Server%3A%20Script%20to%20find%20the%20Size%20of%20Indexes" data-a2a-url="https://www.dbrnd.com/2018/11/sql-server-script-to-find-the-size-of-indexes/" data-a2a-title="SQL Server: Script to find the Size of Indexes"></a></p><p>In this post, I am sharing a script for finding the size of Indexes in SQL Server.<br />
I also shared different DBA scripts on SQL Server Indexes as Find the fragmentation of Indexes, Indexes Statistics.</p>
<blockquote class="wp-embedded-content" data-secret="oBqAEoSQGj"><p><a href="https://www.dbrnd.com/2016/03/sql-server-script-to-find-index-average-fragmentation-in-percentage/">SQL Server: Script to find Index Average Fragmentation in Percentage</a></p></blockquote>
<p><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/03/sql-server-script-to-find-index-average-fragmentation-in-percentage/embed/#?secret=oBqAEoSQGj" data-secret="oBqAEoSQGj" width="600" height="338" title="&#8220;SQL Server: Script to find Index Average Fragmentation in Percentage&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<blockquote class="wp-embedded-content" data-secret="DgzRMrajM7"><p><a href="https://www.dbrnd.com/2016/12/sql-server-script-to-find-outdated-index-statistics-update-it-improve-query-performance/">SQL Server: Script to find Outdated Index Statistics</a></p></blockquote>
<p><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/12/sql-server-script-to-find-outdated-index-statistics-update-it-improve-query-performance/embed/#?secret=DgzRMrajM7" data-secret="DgzRMrajM7" width="600" height="338" title="&#8220;SQL Server: Script to find Outdated Index Statistics&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<p><strong>Using the below script, you can get the size of indexes of a SQL database:</strong></p>
<pre class="crayon-plain-tag">SELECT
    i.name AS IndexName
    ,SUM(s.used_page_count) * 8 AS IndexSizeInKB
FROM sys.dm_db_partition_stats AS s 
INNER JOIN sys.indexes AS i
	ON s.[object_id] = i.[object_id] AND s.index_id = i.index_id
WHERE s.[object_id] = object_id('dbo.Table_Name')
GROUP BY i.name
ORDER BY i.name</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2018/11/sql-server-script-to-find-the-size-of-indexes/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>SQL Server: Script to find the list of Triggers</title>
		<link>https://www.dbrnd.com/2018/10/sql-server-script-to-find-the-list-of-triggers/</link>
					<comments>https://www.dbrnd.com/2018/10/sql-server-script-to-find-the-list-of-triggers/#respond</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 29 Oct 2018 16:16:28 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server DBA Script]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[Audit Trigger]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[Drop Trigger]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Error]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tuning]]></category>
		<category><![CDATA[SQL Server Programming]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[trigger]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=7415</guid>

					<description><![CDATA[In this post, I am sharing a script for getting the list of Triggers in SQL Server. Periodically, we should do the auditing of database hidden triggers. Because triggers are not good for database performance especially for OLTP system. Many times developers are creating triggers for testing purpose and later forget to drop those. SQL [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F10%2Fsql-server-script-to-find-the-list-of-triggers%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20the%20list%20of%20Triggers" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F10%2Fsql-server-script-to-find-the-list-of-triggers%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20the%20list%20of%20Triggers" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F10%2Fsql-server-script-to-find-the-list-of-triggers%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20the%20list%20of%20Triggers" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F10%2Fsql-server-script-to-find-the-list-of-triggers%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20the%20list%20of%20Triggers" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F10%2Fsql-server-script-to-find-the-list-of-triggers%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20the%20list%20of%20Triggers" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F10%2Fsql-server-script-to-find-the-list-of-triggers%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20the%20list%20of%20Triggers" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F10%2Fsql-server-script-to-find-the-list-of-triggers%2F&#038;title=SQL%20Server%3A%20Script%20to%20find%20the%20list%20of%20Triggers" data-a2a-url="https://www.dbrnd.com/2018/10/sql-server-script-to-find-the-list-of-triggers/" data-a2a-title="SQL Server: Script to find the list of Triggers"></a></p><p>In this post, I am sharing a script for getting the list of Triggers in SQL Server. Periodically, we should do the auditing of database hidden triggers. </p>
<p>Because triggers are not good for database performance especially for OLTP system. Many times developers are creating triggers for testing purpose and later forget to drop those. </p>
<blockquote class="wp-embedded-content" data-secret="803rZKZCdm"><p><a href="https://www.dbrnd.com/2016/10/sql-server-encrypted-ddl-trigger-to-track-all-database-changes-to-ensure-database-object-security/">SQL Server: Encrypted DDL Trigger to Track all Database Changes</a></p></blockquote>
<p><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/10/sql-server-encrypted-ddl-trigger-to-track-all-database-changes-to-ensure-database-object-security/embed/#?secret=803rZKZCdm" data-secret="803rZKZCdm" width="600" height="338" title="&#8220;SQL Server: Encrypted DDL Trigger to Track all Database Changes&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<p><strong>Execute the below script and get list of all triggers: </strong></p><pre class="crayon-plain-tag">SELECT 
	sysobjects.name AS TriggerName 
	,USER_NAME(sysobjects.uid) AS TriggerOwner 
	,s.name AS TableSchema 
	,OBJECT_NAME(parent_obj) AS TableName 
	,OBJECTPROPERTY( id, 'ExecIsUpdateTrigger') AS Isupdate 
	,OBJECTPROPERTY( id, 'ExecIsDeleteTrigger') AS Isdelete 
	,OBJECTPROPERTY( id, 'ExecIsInsertTrigger') AS Isinsert 
	,OBJECTPROPERTY( id, 'ExecIsAfterTrigger') AS Isafter 
	,OBJECTPROPERTY( id, 'ExecIsInsteadOfTrigger') AS Isinsteadof
	,OBJECTPROPERTY(id, 'ExecIsTriggerDisabled') AS Isdisabled
FROM sysobjects 
INNER JOIN sysusers 
    ON sysobjects.uid = sysusers.uid 
INNER JOIN sys.tables t 
    ON sysobjects.parent_obj = t.object_id 
INNER JOIN sys.schemas s 
    ON t.schema_id = s.schema_id 
WHERE sysobjects.type = 'TR'</pre><p> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2018/10/sql-server-script-to-find-the-list-of-triggers/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>SQL Server: How to Aggregate data and perform Multiplication?</title>
		<link>https://www.dbrnd.com/2018/10/sql-server-how-to-aggregate-data-and-perform-multiplication/</link>
					<comments>https://www.dbrnd.com/2018/10/sql-server-how-to-aggregate-data-and-perform-multiplication/#respond</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 15 Oct 2018 16:16:00 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Aggregate Function]]></category>
		<category><![CDATA[Aggregate Multiplication]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[EXP]]></category>
		<category><![CDATA[Log]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Error]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tuning]]></category>
		<category><![CDATA[SQL Server Programming]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=7438</guid>

					<description><![CDATA[In this post, I am sharing an aggregate query for calculating Multiplication for each group in SQL Server. We are using an aggregate function like MAX(), SUM(). But there is no any aggregate function for Multiplication. We can use EXP/LOG expression for this exercise. EXP returns the exponential value and LOG returns the natural logarithm [&#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%2F2018%2F10%2Fsql-server-how-to-aggregate-data-and-perform-multiplication%2F&amp;linkname=SQL%20Server%3A%20How%20to%20Aggregate%20data%20and%20perform%20Multiplication%3F" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F10%2Fsql-server-how-to-aggregate-data-and-perform-multiplication%2F&amp;linkname=SQL%20Server%3A%20How%20to%20Aggregate%20data%20and%20perform%20Multiplication%3F" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F10%2Fsql-server-how-to-aggregate-data-and-perform-multiplication%2F&amp;linkname=SQL%20Server%3A%20How%20to%20Aggregate%20data%20and%20perform%20Multiplication%3F" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F10%2Fsql-server-how-to-aggregate-data-and-perform-multiplication%2F&amp;linkname=SQL%20Server%3A%20How%20to%20Aggregate%20data%20and%20perform%20Multiplication%3F" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F10%2Fsql-server-how-to-aggregate-data-and-perform-multiplication%2F&amp;linkname=SQL%20Server%3A%20How%20to%20Aggregate%20data%20and%20perform%20Multiplication%3F" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F10%2Fsql-server-how-to-aggregate-data-and-perform-multiplication%2F&amp;linkname=SQL%20Server%3A%20How%20to%20Aggregate%20data%20and%20perform%20Multiplication%3F" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F10%2Fsql-server-how-to-aggregate-data-and-perform-multiplication%2F&#038;title=SQL%20Server%3A%20How%20to%20Aggregate%20data%20and%20perform%20Multiplication%3F" data-a2a-url="https://www.dbrnd.com/2018/10/sql-server-how-to-aggregate-data-and-perform-multiplication/" data-a2a-title="SQL Server: How to Aggregate data and perform Multiplication?"></a></p><p>In this post, I am sharing an aggregate query for calculating Multiplication for each group in SQL Server. We are using an aggregate function like MAX(), SUM(). But there is no any aggregate function for Multiplication. </p>
<p>We can use EXP/LOG expression for this exercise. EXP returns the exponential value and LOG returns the natural logarithm of the specified float expression.</p>
<p><strong>Please check the below demonstration: </strong></p>
<p><strong>Create a table with sample data:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE tbl_GroupNumber (GroupName VARCHAR(10), GroupValue INT)

INSERT INTO tbl_GroupNumber VALUES
('A',10),('B',15),('C',20),('D',30)
,('B',30),('C',60),('D',40),('D',50)
,('A',70),('B',40),('C',10),('B',90)
GO</pre> </p>
<p><strong>Solution:</strong></p>
<pre class="crayon-plain-tag">SELECT 
	GroupName 
	,EXP(SUM(LOG(GroupValue))) AS GroupValue
FROM tbl_GroupNumber
GROUP BY GroupName</pre> </p>
<p><strong>Result:</strong></p>
<pre class="crayon-plain-tag">GroupName  GroupValue
---------- ----------------------
A          700
B          1620000
C          12000
D          60000</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2018/10/sql-server-how-to-aggregate-data-and-perform-multiplication/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>SQL Server: While execution, Debug the Code and Print the message</title>
		<link>https://www.dbrnd.com/2018/10/sql-server-while-execution-debug-the-code-and-print-the-message/</link>
					<comments>https://www.dbrnd.com/2018/10/sql-server-while-execution-debug-the-code-and-print-the-message/#respond</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 08 Oct 2018 19:38:01 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[RAISE ERROR]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Error]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tuning]]></category>
		<category><![CDATA[SQL Server Programming]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=7454</guid>

					<description><![CDATA[In this post, I am sharing the use of RAISEERROR WITH NOWAIT option of SQL Server which uses for printing the messages and errors while execution of Stored Procedure or any Code block. Using SSMS Debug utility, you can debug your code, but still, developers are liked to debug the code manually by printing the [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F10%2Fsql-server-while-execution-debug-the-code-and-print-the-message%2F&amp;linkname=SQL%20Server%3A%20While%20execution%2C%20Debug%20the%20Code%20and%20Print%20the%20message" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F10%2Fsql-server-while-execution-debug-the-code-and-print-the-message%2F&amp;linkname=SQL%20Server%3A%20While%20execution%2C%20Debug%20the%20Code%20and%20Print%20the%20message" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F10%2Fsql-server-while-execution-debug-the-code-and-print-the-message%2F&amp;linkname=SQL%20Server%3A%20While%20execution%2C%20Debug%20the%20Code%20and%20Print%20the%20message" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F10%2Fsql-server-while-execution-debug-the-code-and-print-the-message%2F&amp;linkname=SQL%20Server%3A%20While%20execution%2C%20Debug%20the%20Code%20and%20Print%20the%20message" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F10%2Fsql-server-while-execution-debug-the-code-and-print-the-message%2F&amp;linkname=SQL%20Server%3A%20While%20execution%2C%20Debug%20the%20Code%20and%20Print%20the%20message" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F10%2Fsql-server-while-execution-debug-the-code-and-print-the-message%2F&amp;linkname=SQL%20Server%3A%20While%20execution%2C%20Debug%20the%20Code%20and%20Print%20the%20message" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F10%2Fsql-server-while-execution-debug-the-code-and-print-the-message%2F&#038;title=SQL%20Server%3A%20While%20execution%2C%20Debug%20the%20Code%20and%20Print%20the%20message" data-a2a-url="https://www.dbrnd.com/2018/10/sql-server-while-execution-debug-the-code-and-print-the-message/" data-a2a-title="SQL Server: While execution, Debug the Code and Print the message"></a></p><p>In this post, I am sharing the use of RAISEERROR WITH NOWAIT option of SQL Server which uses for printing the messages and errors while execution of Stored Procedure or any Code block. </p>
<p>Using SSMS Debug utility, you can debug your code, but still, developers are liked to debug the code manually by printing the inline messages. </p>
<blockquote><p>If you are using the only PRINT command for debugging, you can&#8217;t get the PRINT result while execution.<br />
Additionally, you can add RAISEERROR WITH NOWAIT which returns the message while execution. </p></blockquote>
<p><strong>Check few samples:</strong></p>
<p><strong>Code with only PRINT:</strong><br />
You can get all PRINT results after completion of LOOP. </p>
<pre class="crayon-plain-tag">DECLARE @Count INT

SET @Count = 1

WHILE @COUNT &lt;= 5	
BEGIN
	PRINT @Count
	SET @Count = @Count + 1
	WAITFOR DELAY '00:00:05'
END</pre> </p>
<p><strong>Code with RAISEERROR WITH NOWAIT:</strong><br />
While execution, you can get the result of PRINT. </p>
<pre class="crayon-plain-tag">DECLARE @Count INT

SET @Count = 1

WHILE @COUNT &lt;= 5	
BEGIN
	PRINT @Count
	SET @Count = @Count + 1
	RAISERROR (N'' , 0, 1) WITH NOWAIT
	WAITFOR DELAY '00:00:05'
END</pre> </p>
<p><strong>Stored Procedure with RAISEERROR WITH NOWAIT:</strong><br />
While execution, you can get the result of PRINT. </p>
<pre class="crayon-plain-tag">CREATE PROCEDURE usp_GetData
AS
PRINT 'Debug.....'
RAISERROR (N'' , 0, 1) WITH NOWAIT
WAITFOR DELAY '00:00:05'
GO

EXEC usp_GetData
GO</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2018/10/sql-server-while-execution-debug-the-code-and-print-the-message/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
