<?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 Performance Tunning &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/sql-server-performance-tunning/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:42:10 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.6</generator>
	<item>
		<title>SQL Server: How to compare your objects between two Databases</title>
		<link>https://www.dbrnd.com/2019/08/sql-server-how-to-compare-your-objects-table-view-stored-procedure-trigger-constraint-between-two-databases/</link>
					<comments>https://www.dbrnd.com/2019/08/sql-server-how-to-compare-your-objects-table-view-stored-procedure-trigger-constraint-between-two-databases/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 05 Aug 2019 16:16:04 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server DBA Script]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[compare]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[foreign key]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[Primary key]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tunning]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[stored procedures]]></category>
		<category><![CDATA[tables]]></category>
		<category><![CDATA[trigger]]></category>
		<category><![CDATA[TSQL]]></category>
		<category><![CDATA[views]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=4094</guid>

					<description><![CDATA[When we are working with different versions of database, database professionals are comparing the objects between databases of SQL Server. They must make sure about that all databases are in sync. Using this T-SQL Script, you can compare two databases and find a list of unmatched objects like: Constraints, Tables, Views, Stored Procedure, Triggers. Sample [&#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%2F08%2Fsql-server-how-to-compare-your-objects-table-view-stored-procedure-trigger-constraint-between-two-databases%2F&amp;linkname=SQL%20Server%3A%20How%20to%20compare%20your%20objects%20between%20two%20Databases" 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%2F08%2Fsql-server-how-to-compare-your-objects-table-view-stored-procedure-trigger-constraint-between-two-databases%2F&amp;linkname=SQL%20Server%3A%20How%20to%20compare%20your%20objects%20between%20two%20Databases" 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%2F08%2Fsql-server-how-to-compare-your-objects-table-view-stored-procedure-trigger-constraint-between-two-databases%2F&amp;linkname=SQL%20Server%3A%20How%20to%20compare%20your%20objects%20between%20two%20Databases" 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%2F08%2Fsql-server-how-to-compare-your-objects-table-view-stored-procedure-trigger-constraint-between-two-databases%2F&amp;linkname=SQL%20Server%3A%20How%20to%20compare%20your%20objects%20between%20two%20Databases" 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%2F08%2Fsql-server-how-to-compare-your-objects-table-view-stored-procedure-trigger-constraint-between-two-databases%2F&amp;linkname=SQL%20Server%3A%20How%20to%20compare%20your%20objects%20between%20two%20Databases" 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%2F08%2Fsql-server-how-to-compare-your-objects-table-view-stored-procedure-trigger-constraint-between-two-databases%2F&amp;linkname=SQL%20Server%3A%20How%20to%20compare%20your%20objects%20between%20two%20Databases" 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%2F08%2Fsql-server-how-to-compare-your-objects-table-view-stored-procedure-trigger-constraint-between-two-databases%2F&#038;title=SQL%20Server%3A%20How%20to%20compare%20your%20objects%20between%20two%20Databases" data-a2a-url="https://www.dbrnd.com/2019/08/sql-server-how-to-compare-your-objects-table-view-stored-procedure-trigger-constraint-between-two-databases/" data-a2a-title="SQL Server: How to compare your objects between two Databases"></a></p><p>When we are working with different versions of database, database professionals are comparing the objects between databases of SQL Server.<br />
They must make sure about that all databases are in sync. </p>
<blockquote><p>Using this T-SQL Script, you can compare two databases and find a list of unmatched objects like: Constraints, Tables, Views, Stored Procedure, Triggers. </p></blockquote>
<p><strong>Sample demonstration:</strong><br />
<strong>First, Create two sample databases:<br />
</strong></p>
<pre class="crayon-plain-tag">CREATE DATABASE ABC
GO
CREATE DATABASE XYZ
GO</pre> </p>
<p><strong>Create few sample tables in both the databases:<br />
</strong></p><pre class="crayon-plain-tag">CREATE TABLE ABC.dbo.tbl_Test
(
	ID INT
	,MyDate DATE
)
GO

CREATE TABLE ABC.dbo.tbl_MyTest
(
	ID INT
	,Name VARCHAR(50)
)
GO

CREATE TABLE XYZ.dbo.tbl_Test
(
	ID INT
	,MyDate DATE
)
GO

CREATE TABLE XYZ.dbo.tbl_MyFinal
(
	ID INT
	,Name VARCHAR(50)
)
GO</pre><p> </p>
<p><strong>T-SQL Script to compare objects between two databases:</strong><br />
According to your databases, You can change the name of @SourceDatabase and @DestinationDatabase.</p>
<pre class="crayon-plain-tag">DECLARE @SourceDatabase VARCHAR(50) 
DECLARE @DestinationDatabase VARCHAR(50) 
DECLARE @SQL VARCHAR(MAX) 
     
SELECT @SourceDatabase = 'ABC' 
SELECT @DestinationDatabase = 'XYZ'
     
SELECT @SQL = 
'
	SELECT 
		ISNULL(S.name,D.name) ObjectName
		,CASE  
			WHEN S.object_id IS NULL 
				THEN D.type_desc + '' is missing in the Source Database: '	+ @SourceDatabase + ''' 
			WHEN D.object_id IS NULL 
				THEN S.type_desc +  '' is missing in the Destination Database: ' + @DestinationDatabase + ''' 
		END ''Status'' 
	FROM 
	(
		SELECT * FROM ' + @SourceDatabase + '.SYS.objects  
		WHERE Type_desc not in (''INTERNAL_TABLE'',''SYSTEM_TABLE'',''SERVICE_QUEUE'')
	) AS S  
	FULL OUTER JOIN 
	(
		SELECT * FROM ' + @DestinationDatabase + '.SYS.objects  
		WHERE Type_desc not in (''INTERNAL_TABLE'',''SYSTEM_TABLE'',''SERVICE_QUEUE'')
	) AS D 
	ON S.name = D.name 
		AND S.type = D.type 
	ORDER BY isnull(S.type,D.type)
'  
EXEC (@Sql)</pre> </p>
<p><strong>The Result:</strong></p>
<pre class="crayon-plain-tag">ObjectName                         Status
------------------  -------------------------------------------------------
tbl_Test              NULL
tbl_MyFinal           USER_TABLE is missing in the Source Database: ABC
tbl_MyTest            USER_TABLE is missing in the Destination Database: XYZ</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2019/08/sql-server-how-to-compare-your-objects-table-view-stored-procedure-trigger-constraint-between-two-databases/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>SQL Server: Script to find the total size of the Indexes</title>
		<link>https://www.dbrnd.com/2019/05/sql-server-script-to-find-the-total-size-of-the-indexes/</link>
					<comments>https://www.dbrnd.com/2019/05/sql-server-script-to-find-the-total-size-of-the-indexes/#respond</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 27 May 2019 16:16:18 +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[duplicate index]]></category>
		<category><![CDATA[fragmentation]]></category>
		<category><![CDATA[index]]></category>
		<category><![CDATA[redundant index]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tunning]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=4191</guid>

					<description><![CDATA[In this post, I am sharing one script to find the size of Indexes in SQL Server. The first step for performance optimization is to measure the size of tables and indexes which helps you to find out more about fragmentation. I have already shared a couple of articles on SQL Server Indexes like: find [&#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%2F05%2Fsql-server-script-to-find-the-total-size-of-the-indexes%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20the%20total%20size%20of%20the%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%2F2019%2F05%2Fsql-server-script-to-find-the-total-size-of-the-indexes%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20the%20total%20size%20of%20the%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%2F2019%2F05%2Fsql-server-script-to-find-the-total-size-of-the-indexes%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20the%20total%20size%20of%20the%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%2F2019%2F05%2Fsql-server-script-to-find-the-total-size-of-the-indexes%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20the%20total%20size%20of%20the%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%2F2019%2F05%2Fsql-server-script-to-find-the-total-size-of-the-indexes%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20the%20total%20size%20of%20the%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%2F2019%2F05%2Fsql-server-script-to-find-the-total-size-of-the-indexes%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20the%20total%20size%20of%20the%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%2F2019%2F05%2Fsql-server-script-to-find-the-total-size-of-the-indexes%2F&#038;title=SQL%20Server%3A%20Script%20to%20find%20the%20total%20size%20of%20the%20Indexes" data-a2a-url="https://www.dbrnd.com/2019/05/sql-server-script-to-find-the-total-size-of-the-indexes/" data-a2a-title="SQL Server: Script to find the total size of the Indexes"></a></p><p>In this post, I am sharing one script to find the size of Indexes in SQL Server.</p>
<blockquote><p>The first step for performance optimization is to measure the size of tables and indexes which helps you to find out more about fragmentation.</p></blockquote>
<p>I have already shared a couple of articles on SQL Server Indexes like: find duplicate indexes, unused indexes and fragmentation of indexes. </p>
<p>You can also access these articles after below T-SQL. </p>
<pre class="crayon-plain-tag">SELECT
	OBJECT_SCHEMA_NAME(i.OBJECT_ID) AS SchemaName
	,OBJECT_NAME(i.OBJECT_ID) AS TableName
	,i.name AS IndexName
	,8 * SUM(au.used_pages) AS IndexSizeInKB
FROM sys.indexes AS i
JOIN sys.partitions AS p 
	ON p.OBJECT_ID = i.OBJECT_ID 
		AND p.index_id = i.index_id
JOIN sys.allocation_units AS au 
	ON au.container_id = p.partition_id
GROUP BY 
	i.OBJECT_ID
	,i.index_id
	,i.name
ORDER BY OBJECT_NAME(i.OBJECT_ID),i.index_id</pre> </p>
<p><strong>Other related articles:</strong></p>
<blockquote class="wp-embedded-content" data-secret="iWrp53ltXi"><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=iWrp53ltXi" data-secret="iWrp53ltXi" 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="kFuNrnjgJI"><p><a href="https://www.dbrnd.com/2016/11/sql-server-script-to-find-redundant-and-duplicate-indexes/">SQL Server: Script to find Redundant and Duplicate Indexes</a></p></blockquote>
<p><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/11/sql-server-script-to-find-redundant-and-duplicate-indexes/embed/#?secret=kFuNrnjgJI" data-secret="kFuNrnjgJI" width="600" height="338" title="&#8220;SQL Server: Script to find Redundant and Duplicate Indexes&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<blockquote class="wp-embedded-content" data-secret="CLStlFpaQE"><p><a href="https://www.dbrnd.com/2015/10/sql-server-script-to-find-usage-of-database-indexes/">SQL Server: Script to find usage of Database Indexes</a></p></blockquote>
<p><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2015/10/sql-server-script-to-find-usage-of-database-indexes/embed/#?secret=CLStlFpaQE" data-secret="CLStlFpaQE" width="600" height="338" title="&#8220;SQL Server: Script to find usage of Database Indexes&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<blockquote class="wp-embedded-content" data-secret="CuRotuXr6g"><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=CuRotuXr6g" data-secret="CuRotuXr6g" 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>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2019/05/sql-server-script-to-find-the-total-size-of-the-indexes/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>SQL Server: How to find a time when was SQL Server Restarted</title>
		<link>https://www.dbrnd.com/2019/05/sql-server-how-to-find-a-time-when-was-sql-server-restarted-dm_exec_sessions-dm_os_sys_info-traces/</link>
					<comments>https://www.dbrnd.com/2019/05/sql-server-how-to-find-a-time-when-was-sql-server-restarted-dm_exec_sessions-dm_os_sys_info-traces/#respond</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 20 May 2019 16:16:01 +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[SQL Query]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tunning]]></category>
		<category><![CDATA[SQL Server Restart]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[sys.databases]]></category>
		<category><![CDATA[sys.dm_exec_sessions]]></category>
		<category><![CDATA[sys.traces]]></category>
		<category><![CDATA[sysdatabases]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=4089</guid>

					<description><![CDATA[In this post, I am sharing few different scripts to find when was the SQL Server restarted. The DBAs must know about this because they have to make sure about data consistency. For example: when SQL Server restarted because of power failure, system failure, update failure or any other reason, We must check the last [&#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%2F05%2Fsql-server-how-to-find-a-time-when-was-sql-server-restarted-dm_exec_sessions-dm_os_sys_info-traces%2F&amp;linkname=SQL%20Server%3A%20How%20to%20find%20a%20time%20when%20was%20SQL%20Server%20Restarted" 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%2F05%2Fsql-server-how-to-find-a-time-when-was-sql-server-restarted-dm_exec_sessions-dm_os_sys_info-traces%2F&amp;linkname=SQL%20Server%3A%20How%20to%20find%20a%20time%20when%20was%20SQL%20Server%20Restarted" 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%2F05%2Fsql-server-how-to-find-a-time-when-was-sql-server-restarted-dm_exec_sessions-dm_os_sys_info-traces%2F&amp;linkname=SQL%20Server%3A%20How%20to%20find%20a%20time%20when%20was%20SQL%20Server%20Restarted" 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%2F05%2Fsql-server-how-to-find-a-time-when-was-sql-server-restarted-dm_exec_sessions-dm_os_sys_info-traces%2F&amp;linkname=SQL%20Server%3A%20How%20to%20find%20a%20time%20when%20was%20SQL%20Server%20Restarted" 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%2F05%2Fsql-server-how-to-find-a-time-when-was-sql-server-restarted-dm_exec_sessions-dm_os_sys_info-traces%2F&amp;linkname=SQL%20Server%3A%20How%20to%20find%20a%20time%20when%20was%20SQL%20Server%20Restarted" 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%2F05%2Fsql-server-how-to-find-a-time-when-was-sql-server-restarted-dm_exec_sessions-dm_os_sys_info-traces%2F&amp;linkname=SQL%20Server%3A%20How%20to%20find%20a%20time%20when%20was%20SQL%20Server%20Restarted" 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%2F05%2Fsql-server-how-to-find-a-time-when-was-sql-server-restarted-dm_exec_sessions-dm_os_sys_info-traces%2F&#038;title=SQL%20Server%3A%20How%20to%20find%20a%20time%20when%20was%20SQL%20Server%20Restarted" data-a2a-url="https://www.dbrnd.com/2019/05/sql-server-how-to-find-a-time-when-was-sql-server-restarted-dm_exec_sessions-dm_os_sys_info-traces/" data-a2a-title="SQL Server: How to find a time when was SQL Server Restarted"></a></p><p>In this post, I am sharing few different scripts to find when was the SQL Server restarted.</p>
<blockquote><p>The DBAs must know about this because they have to make sure about data consistency.
</p></blockquote>
<blockquote><p>For example: when SQL Server restarted because of power failure, system failure, update failure or any other reason, We must check the last restarted time of SQL Server. Because from that time, we have to restore data from our backup disks to the actual disk.</p></blockquote>
<blockquote><p>When SQL Server restarted, few transactions also rollback. We have to also identify these transactions by knowing the correct time when SQL Server actually restarted.
</p></blockquote>
<p><strong>Using sys.dm_exec_sessions:</strong></p>
<pre class="crayon-plain-tag">SELECT login_time FROM sys.dm_exec_sessions WHERE session_id = 1
GO</pre> </p>
<p><strong>Using sys.dm_os_sys_info:</strong></p>
<pre class="crayon-plain-tag">SELECT sqlserver_start_time FROM sys.dm_os_sys_info
GO</pre> </p>
<p><strong>Using sys.databases:</strong></p>
<pre class="crayon-plain-tag">SELECT create_date FROM sys.databases WHERE name = 'tempdb' 
GO</pre> </p>
<p><strong>Using sys.traces:</strong></p>
<pre class="crayon-plain-tag">SELECT start_time FROM sys.traces WHERE is_default = 1  
GO</pre> </p>
<p><strong>Using sysdatabases: </strong></p>
<pre class="crayon-plain-tag">SELECT crdate FROM sysdatabases WHERE name='tempdb'  
GO</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2019/05/sql-server-how-to-find-a-time-when-was-sql-server-restarted-dm_exec_sessions-dm_os_sys_info-traces/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>SQL Server: Find Stored Procedures which use Dynamic SQL and Temporary Table</title>
		<link>https://www.dbrnd.com/2019/04/sql-server-find-stored-procedures-which-use-dynamic-sql-and-temporary-table/</link>
					<comments>https://www.dbrnd.com/2019/04/sql-server-find-stored-procedures-which-use-dynamic-sql-and-temporary-table/#respond</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 08 Apr 2019 18:30:46 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server DBA Script]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[Data Security]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[dynamic sql]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[SQL Injection]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tunning]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[Stored Procedure]]></category>
		<category><![CDATA[Temp Table]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=4076</guid>

					<description><![CDATA[Whenever you are searching for SQL query optimization tips or prevent SQL injection tips, you can find few common suggestions like: Please do not use Dynamic SQL in your Stored Procedure. Please try to avoid the use of Temp Tables. I always tell to database developers, please try to avoid the use of Dynamic SQL [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F04%2Fsql-server-find-stored-procedures-which-use-dynamic-sql-and-temporary-table%2F&amp;linkname=SQL%20Server%3A%20Find%20Stored%20Procedures%20which%20use%20Dynamic%20SQL%20and%20Temporary%20Table" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F04%2Fsql-server-find-stored-procedures-which-use-dynamic-sql-and-temporary-table%2F&amp;linkname=SQL%20Server%3A%20Find%20Stored%20Procedures%20which%20use%20Dynamic%20SQL%20and%20Temporary%20Table" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F04%2Fsql-server-find-stored-procedures-which-use-dynamic-sql-and-temporary-table%2F&amp;linkname=SQL%20Server%3A%20Find%20Stored%20Procedures%20which%20use%20Dynamic%20SQL%20and%20Temporary%20Table" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F04%2Fsql-server-find-stored-procedures-which-use-dynamic-sql-and-temporary-table%2F&amp;linkname=SQL%20Server%3A%20Find%20Stored%20Procedures%20which%20use%20Dynamic%20SQL%20and%20Temporary%20Table" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F04%2Fsql-server-find-stored-procedures-which-use-dynamic-sql-and-temporary-table%2F&amp;linkname=SQL%20Server%3A%20Find%20Stored%20Procedures%20which%20use%20Dynamic%20SQL%20and%20Temporary%20Table" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F04%2Fsql-server-find-stored-procedures-which-use-dynamic-sql-and-temporary-table%2F&amp;linkname=SQL%20Server%3A%20Find%20Stored%20Procedures%20which%20use%20Dynamic%20SQL%20and%20Temporary%20Table" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2019%2F04%2Fsql-server-find-stored-procedures-which-use-dynamic-sql-and-temporary-table%2F&#038;title=SQL%20Server%3A%20Find%20Stored%20Procedures%20which%20use%20Dynamic%20SQL%20and%20Temporary%20Table" data-a2a-url="https://www.dbrnd.com/2019/04/sql-server-find-stored-procedures-which-use-dynamic-sql-and-temporary-table/" data-a2a-title="SQL Server: Find Stored Procedures which use Dynamic SQL and Temporary Table"></a></p><p>Whenever you are searching for SQL query optimization tips or prevent SQL injection tips, you can find few common suggestions like: Please do not use Dynamic SQL in your Stored Procedure. Please try to avoid the use of Temp Tables.</p>
<blockquote><p>I always tell to database developers, please try to avoid the use of Dynamic SQL and Temp Table in your Stored Procedures.</p></blockquote>
<blockquote><p>A Temp Table requires additional CPU/IO which degrades the query performance. A Dynamic SQL is not safe against the SQL Injection and It also compiles data every time which requires more Memory. </p></blockquote>
<blockquote><p>Here, I am sharing one of the important scripts which gives you list of SQL Server Stored Procedures, which use the Dynamic SQL and Temp Table.<br />
You can easily get the list of Stored Procedures and can make plans of modifying it.</p></blockquote>
<blockquote><p>Prepared this script using sys.dm_exec_describe_first_result_set and sys.procedures where error number 4 = Dynamic SQL and error number 10 = Temporary Table.</p></blockquote>
<pre class="crayon-plain-tag">SELECT  
	SP_Name
	,error_message
	,error_type_desc 
FROM (SELECT schema_name(schema_id)+'.'+name SP_Name FROM sys.procedures) AS T
CROSS APPLY sys.dm_exec_describe_first_result_set (SP_Name, NULL, 0) 
WHERE error_type IN (4,10)</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2019/04/sql-server-find-stored-procedures-which-use-dynamic-sql-and-temporary-table/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>SQL Server: Auto Generate Database Detach and Attach Scripts</title>
		<link>https://www.dbrnd.com/2019/01/sql-server-auto-generate-database-detach-and-attach-scripts-single_user-multi_user-database-mode-data-migration/</link>
					<comments>https://www.dbrnd.com/2019/01/sql-server-auto-generate-database-detach-and-attach-scripts-single_user-multi_user-database-mode-data-migration/#respond</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 28 Jan 2019 16:16:23 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server DBA Script]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[attach]]></category>
		<category><![CDATA[data migration]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[detach]]></category>
		<category><![CDATA[multi_user]]></category>
		<category><![CDATA[single_user]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tunning]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=4070</guid>

					<description><![CDATA[In this post, I am sharing two different scripts to populate attach and detach scripts for all your SQL Server Databases. When we are migrating our SQL Database Server, we require to move all databases from one server to another server. If you have a big number of databases, making of individual attach and detach [&#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-auto-generate-database-detach-and-attach-scripts-single_user-multi_user-database-mode-data-migration%2F&amp;linkname=SQL%20Server%3A%20Auto%20Generate%20Database%20Detach%20and%20Attach%20Scripts" 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-auto-generate-database-detach-and-attach-scripts-single_user-multi_user-database-mode-data-migration%2F&amp;linkname=SQL%20Server%3A%20Auto%20Generate%20Database%20Detach%20and%20Attach%20Scripts" 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-auto-generate-database-detach-and-attach-scripts-single_user-multi_user-database-mode-data-migration%2F&amp;linkname=SQL%20Server%3A%20Auto%20Generate%20Database%20Detach%20and%20Attach%20Scripts" 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-auto-generate-database-detach-and-attach-scripts-single_user-multi_user-database-mode-data-migration%2F&amp;linkname=SQL%20Server%3A%20Auto%20Generate%20Database%20Detach%20and%20Attach%20Scripts" 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-auto-generate-database-detach-and-attach-scripts-single_user-multi_user-database-mode-data-migration%2F&amp;linkname=SQL%20Server%3A%20Auto%20Generate%20Database%20Detach%20and%20Attach%20Scripts" 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-auto-generate-database-detach-and-attach-scripts-single_user-multi_user-database-mode-data-migration%2F&amp;linkname=SQL%20Server%3A%20Auto%20Generate%20Database%20Detach%20and%20Attach%20Scripts" 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-auto-generate-database-detach-and-attach-scripts-single_user-multi_user-database-mode-data-migration%2F&#038;title=SQL%20Server%3A%20Auto%20Generate%20Database%20Detach%20and%20Attach%20Scripts" data-a2a-url="https://www.dbrnd.com/2019/01/sql-server-auto-generate-database-detach-and-attach-scripts-single_user-multi_user-database-mode-data-migration/" data-a2a-title="SQL Server: Auto Generate Database Detach and Attach Scripts"></a></p><p>In this post, I am sharing two different scripts to populate attach and detach scripts for all your SQL Server Databases.</p>
<blockquote><p>When we are migrating our SQL Database Server, we require to move all databases from one server to another server.</p>
<p>If you have a big number of databases, making of individual attach and detach script will take more time. </p></blockquote>
<blockquote><p>I have also added script to change database access mode like: Multi_User to Single_User for Detach Process and Single_User to Multi_User for Attach Process. </p>
<p>If your database is in use, you may require to change the database access mode to close all running connections.</p></blockquote>
<p>Using this script you can populate attach and detach scripts for all databases.<br />
<strong>Execute this script to generate detach scripts for all databases:</strong></p>
<pre class="crayon-plain-tag">DECLARE @DatabaseName AS VARCHAR(255)
DECLARE CurDetach CURSOR FOR
  
  SELECT name
  FROM   MASTER.sys.databases
  WHERE  owner_sid &gt; 1;

OPEN CurDetach
FETCH Next FROM CurDetach INTO @DatabaseName
WHILE @@FETCH_STATUS = 0
  BEGIN      
	  PRINT 
		'ALTER DATABASE ' + @DatabaseName + ' SET SINGLE_USER WITH ROLLBACK IMMEDIATE' 
		+ CHAR(10) + ' GO' + CHAR(10) +
		'sp_detach_db ' + @DatabaseName + CHAR(10)
		+ ' GO' + CHAR(10) + 'Print ''Detach of '
		+ @DatabaseName
		+ ' database completed successfully'''
		+ CHAR(10) + ' GO'

      FETCH NEXT FROM CurDetach INTO @DatabaseName
  END

CLOSE CurDetach
DEALLOCATE CurDetach</pre> </p>
<p><strong>Execute this script to generate attach scripts for all databases:</strong><br />
You can change your file name or file path using @Filepath variable.</p>
<pre class="crayon-plain-tag">DECLARE @DatabaseName AS VARCHAR(255)
DECLARE @Filepath AS VARCHAR(255)

SET @Filepath = 'C:\SQLDATA\'

DECLARE CurAttach CURSOR FOR
  SELECT name
  FROM   MASTER.sys.databases
  WHERE  owner_sid &gt; 1;

OPEN CurAttach
FETCH Next FROM CurAttach INTO @DatabaseName
WHILE @@FETCH_STATUS = 0
  BEGIN      
	  PRINT 
		'CREATE DATABASE ' + @DatabaseName + ' ON
		(FILENAME = '+ @Filepath + @DatabaseName +'.mdf)
		,(FILENAME = '+ @Filepath + @DatabaseName +'.ldf)
		FOR ATTACH
		GO

		ALTER DATABASE '+ @DatabaseName +' SET MULTI_USER WITH ROLLBACK IMMEDIATE
		GO'
      FETCH NEXT FROM CurAttach INTO @DatabaseName
  END

CLOSE CurAttach
DEALLOCATE CurAttach</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2019/01/sql-server-auto-generate-database-detach-and-attach-scripts-single_user-multi_user-database-mode-data-migration/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>SQL Server: Script to find a list of Weekends between two Dates</title>
		<link>https://www.dbrnd.com/2019/01/sql-server-script-to-find-a-list-of-weekends-between-two-dates-dba-maintenance-work/</link>
					<comments>https://www.dbrnd.com/2019/01/sql-server-script-to-find-a-list-of-weekends-between-two-dates-dba-maintenance-work/#respond</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 21 Jan 2019 07:09:51 +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[dba activity]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[EOMONTH]]></category>
		<category><![CDATA[maintenance]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tunning]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[TSQL]]></category>
		<category><![CDATA[weekend]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=4067</guid>

					<description><![CDATA[In this post, I am sharing one script to find a list of Weekends between given two Dates in SQL Server. If you are a database developer and reading this post, you should know about the life of DBA. Database Administrator life is for 24*7 and they have to also set few maintenance tasks over [&#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-script-to-find-a-list-of-weekends-between-two-dates-dba-maintenance-work%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20a%20list%20of%20Weekends%20between%20two%20Dates" 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-script-to-find-a-list-of-weekends-between-two-dates-dba-maintenance-work%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20a%20list%20of%20Weekends%20between%20two%20Dates" 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-script-to-find-a-list-of-weekends-between-two-dates-dba-maintenance-work%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20a%20list%20of%20Weekends%20between%20two%20Dates" 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-script-to-find-a-list-of-weekends-between-two-dates-dba-maintenance-work%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20a%20list%20of%20Weekends%20between%20two%20Dates" 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-script-to-find-a-list-of-weekends-between-two-dates-dba-maintenance-work%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20a%20list%20of%20Weekends%20between%20two%20Dates" 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-script-to-find-a-list-of-weekends-between-two-dates-dba-maintenance-work%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20find%20a%20list%20of%20Weekends%20between%20two%20Dates" 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-script-to-find-a-list-of-weekends-between-two-dates-dba-maintenance-work%2F&#038;title=SQL%20Server%3A%20Script%20to%20find%20a%20list%20of%20Weekends%20between%20two%20Dates" data-a2a-url="https://www.dbrnd.com/2019/01/sql-server-script-to-find-a-list-of-weekends-between-two-dates-dba-maintenance-work/" data-a2a-title="SQL Server: Script to find a list of Weekends between two Dates"></a></p><p>In this post, I am sharing one script to find a list of Weekends between given two Dates in SQL Server.</p>
<blockquote><p>If you are a database developer and reading this post, you should know about the life of DBA.<br />
Database Administrator life is for 24*7 and they have to also set few maintenance tasks over the weekends and holidays. </p></blockquote>
<blockquote><p>This script helps to DBA for finding available weekends between the dates so they can set auto-schedule for database maintenance.</p></blockquote>
<p><strong>Please access few related articles:</strong></p>
<blockquote class="wp-embedded-content" data-secret="VRCL4CschW"><p><a href="https://www.dbrnd.com/2016/07/a-day-in-the-life-of-a-dba-database-administrator/">A Day in the life of a DBA !</a></p></blockquote>
<p><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/07/a-day-in-the-life-of-a-dba-database-administrator/embed/#?secret=VRCL4CschW" data-secret="VRCL4CschW" width="600" height="338" title="&#8220;A Day in the life of a DBA !&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<blockquote class="wp-embedded-content" data-secret="Fdmay8AehU"><p><a href="https://www.dbrnd.com/2016/01/sql-server-2012-find-first-sunday-of-next-month-using-eomonth/">SQL Server 2012: Find First Sunday of Next Month using EOMONTH</a></p></blockquote>
<p><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/01/sql-server-2012-find-first-sunday-of-next-month-using-eomonth/embed/#?secret=Fdmay8AehU" data-secret="Fdmay8AehU" width="600" height="338" title="&#8220;SQL Server 2012: Find First Sunday of Next Month using EOMONTH&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<pre class="crayon-plain-tag">DECLARE @beginDate DATE = '20161201'
DECLARE @endDate DATE = '20161231'  
 
DECLARE @Weekend TABLE
(
	Weekend DATE PRIMARY KEY
	,IsWeekend BIT
)
 
WHILE @beginDate &lt;= @endDate 
BEGIN 
INSERT INTO @Weekend 
SELECT 
	@beginDate AS Weekend 
	,(CASE WHEN DATEPART(WEEKDAY, @beginDate) In (7, 1) THEN 1 ELSE 0 END) AS IsWeekend 
	SET @beginDate = DateAdd(Day, 1, @beginDate) 
END
 
SELECT Weekend FROM @Weekend WHERE IsWeekend = 1</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2019/01/sql-server-script-to-find-a-list-of-weekends-between-two-dates-dba-maintenance-work/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>SQL Server: Script to take full backup for all the Databases</title>
		<link>https://www.dbrnd.com/2019/01/sql-server-script-to-take-full-backup-for-all-the-databases-ad-hoc-full-database-backup/</link>
					<comments>https://www.dbrnd.com/2019/01/sql-server-script-to-take-full-backup-for-all-the-databases-ad-hoc-full-database-backup/#respond</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 14 Jan 2019 07:03:32 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server DBA Script]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[auto backup]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database backup script]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[full backup]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tunning]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=4041</guid>

					<description><![CDATA[In this post, I am sharing one T-SQL Script to take full backup for all the databases of SQL Server. There are different types of backups and techniques available in the SQL Server, but I always believe in DBA Scripts which you can modify as per your requirements. Apart from scheduled backups, sometimes DBA requires [&#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-script-to-take-full-backup-for-all-the-databases-ad-hoc-full-database-backup%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20take%20full%20backup%20for%20all%20the%20Databases" 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-script-to-take-full-backup-for-all-the-databases-ad-hoc-full-database-backup%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20take%20full%20backup%20for%20all%20the%20Databases" 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-script-to-take-full-backup-for-all-the-databases-ad-hoc-full-database-backup%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20take%20full%20backup%20for%20all%20the%20Databases" 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-script-to-take-full-backup-for-all-the-databases-ad-hoc-full-database-backup%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20take%20full%20backup%20for%20all%20the%20Databases" 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-script-to-take-full-backup-for-all-the-databases-ad-hoc-full-database-backup%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20take%20full%20backup%20for%20all%20the%20Databases" 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-script-to-take-full-backup-for-all-the-databases-ad-hoc-full-database-backup%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20take%20full%20backup%20for%20all%20the%20Databases" 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-script-to-take-full-backup-for-all-the-databases-ad-hoc-full-database-backup%2F&#038;title=SQL%20Server%3A%20Script%20to%20take%20full%20backup%20for%20all%20the%20Databases" data-a2a-url="https://www.dbrnd.com/2019/01/sql-server-script-to-take-full-backup-for-all-the-databases-ad-hoc-full-database-backup/" data-a2a-title="SQL Server: Script to take full backup for all the Databases"></a></p><p>In this post, I am sharing one T-SQL Script to take full backup for all the databases of SQL Server. </p>
<blockquote><p>There are different types of backups and techniques available in the SQL Server, but I always believe in DBA Scripts which you can modify as per your requirements.
</p></blockquote>
<blockquote><p>Apart from scheduled backups, sometimes DBA requires ad-hoc full backups of databases which they can do using this script.</p></blockquote>
<p><strong>Script to take full backup of databases:</strong><br />
You can change the path name (&#8216;C:\TempBackup\&#8217;) and replace with your path name. </p>
<pre class="crayon-plain-tag">DECLARE @dbName	NVARCHAR (255); 
DECLARE @SQL NVARCHAR(4000); 
 
DECLARE DBBackupCur 
CURSOR FOR 
    SELECT name FROM sys.databases WITH (NOLOCK) 
    WHERE name NOT IN ('master','model','msdb','tempdb')  
    OPTION (RECOMPILE); 
 
OPEN DBBackupCur;     
FETCH NEXT FROM DBBackupCur INTO @dbName 
WHILE (@@fetch_status &lt;&gt; -1) 
BEGIN 
    IF (@@fetch_status &lt;&gt; -2) 
    BEGIN 
        SET @SQL = N'BACKUP DATABASE [' + @dbName + N'] TO DISK = ''C:\TempBackup\' + @dbName + N'.bak'''; 
        EXECUTE sp_executesql @SQL 
        PRINT N'Backup completed: ' + @dbName 
    END; 
    FETCH NEXT FROM DBBackupCur INTO @dbName; 
END; 
CLOSE DBBackupCur; 
DEALLOCATE DBBackupCur; 
GO</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2019/01/sql-server-script-to-take-full-backup-for-all-the-databases-ad-hoc-full-database-backup/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>SQL Server Interview: Primary Key Column as Non Clustered Index, Non Primary Key Column as Clustered Index</title>
		<link>https://www.dbrnd.com/2018/03/sql-server-interview-primary-key-column-as-non-clustered-index-non-primary-key-column-as-clustered-index/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Sat, 10 Mar 2018 16:16:36 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server Interview]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[clustered index]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[Nonclustered Index]]></category>
		<category><![CDATA[Primary key]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tunning]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=4236</guid>

					<description><![CDATA[In this post, I am sharing an important interview question for SQL Server Database Developer. The question is: Can we apply Non-clustered Index on Primary Key Column, Can we apply Clustered Index on Non-Primary key column? Last year we arranged a walk in interview for SQL Server Developer. I had taken around 19 f2f interviews [&#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%2F03%2Fsql-server-interview-primary-key-column-as-non-clustered-index-non-primary-key-column-as-clustered-index%2F&amp;linkname=SQL%20Server%20Interview%3A%20Primary%20Key%20Column%20as%20Non%20Clustered%20Index%2C%20Non%20Primary%20Key%20Column%20as%20Clustered%20Index" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F03%2Fsql-server-interview-primary-key-column-as-non-clustered-index-non-primary-key-column-as-clustered-index%2F&amp;linkname=SQL%20Server%20Interview%3A%20Primary%20Key%20Column%20as%20Non%20Clustered%20Index%2C%20Non%20Primary%20Key%20Column%20as%20Clustered%20Index" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F03%2Fsql-server-interview-primary-key-column-as-non-clustered-index-non-primary-key-column-as-clustered-index%2F&amp;linkname=SQL%20Server%20Interview%3A%20Primary%20Key%20Column%20as%20Non%20Clustered%20Index%2C%20Non%20Primary%20Key%20Column%20as%20Clustered%20Index" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F03%2Fsql-server-interview-primary-key-column-as-non-clustered-index-non-primary-key-column-as-clustered-index%2F&amp;linkname=SQL%20Server%20Interview%3A%20Primary%20Key%20Column%20as%20Non%20Clustered%20Index%2C%20Non%20Primary%20Key%20Column%20as%20Clustered%20Index" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F03%2Fsql-server-interview-primary-key-column-as-non-clustered-index-non-primary-key-column-as-clustered-index%2F&amp;linkname=SQL%20Server%20Interview%3A%20Primary%20Key%20Column%20as%20Non%20Clustered%20Index%2C%20Non%20Primary%20Key%20Column%20as%20Clustered%20Index" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F03%2Fsql-server-interview-primary-key-column-as-non-clustered-index-non-primary-key-column-as-clustered-index%2F&amp;linkname=SQL%20Server%20Interview%3A%20Primary%20Key%20Column%20as%20Non%20Clustered%20Index%2C%20Non%20Primary%20Key%20Column%20as%20Clustered%20Index" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F03%2Fsql-server-interview-primary-key-column-as-non-clustered-index-non-primary-key-column-as-clustered-index%2F&#038;title=SQL%20Server%20Interview%3A%20Primary%20Key%20Column%20as%20Non%20Clustered%20Index%2C%20Non%20Primary%20Key%20Column%20as%20Clustered%20Index" data-a2a-url="https://www.dbrnd.com/2018/03/sql-server-interview-primary-key-column-as-non-clustered-index-non-primary-key-column-as-clustered-index/" data-a2a-title="SQL Server Interview: Primary Key Column as Non Clustered Index, Non Primary Key Column as Clustered Index"></a></p><p>In this post, I am sharing an important interview question for SQL Server Database Developer.</p>
<p><strong>The question is:</strong></p>
<blockquote><p><strong>Can we apply Non-clustered Index on Primary Key Column, Can we apply Clustered Index on Non-Primary key column?</strong></p></blockquote>
<blockquote><p>Last year we arranged a walk in interview for SQL Server Developer. I had taken around 19 f2f interviews and prepared list of questions for another 88 f2f interviews. </p></blockquote>
<blockquote><p>I asked this question to all 19 candidates and 16 candidates said, we cannot create a Non-clustered Index on Primary Key because Primary Key has a default Clustered Index.<br />
This is wrong, You can create Non-clustered Primary key and can apply Clustered Index on Non-Primary key column.</p></blockquote>
<p>The main reason for this confusion is, SQL Server creates default Clustered Index on the Primary Key column. </p>
<p><strong>Our answer should be like:</strong> <em>Yes, we can define Non-Clustered Primary key column and can define Clustered index on other Non-Primary Key column.</em></p>
<blockquote><p>But the best practice is to define a Primary Key as Clustered Index because Unique value + Physical Order of data returns good query performance.</p></blockquote>
<p>In most of the cases, we are joining data using our Primary Key column, but If we require our main joining on other Non-Primary column and also require records basis on that Non-Primary column data order, we should apply Clustered Index on that Non-Primary key column. </p>
<p><strong>T-SQL Script to create NonClustered Primary Key and Clustered Index Non-Primary key column:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE tbl_Students
(
	StudID INT 
	,StudName VARCHAR(20)
	,CONSTRAINT pk_tbl_Students_StudID PRIMARY KEY NONCLUSTERED (StudID)
)
GO

CREATE CLUSTERED INDEX idx_tbl_Students_StudName ON tbl_Students (StudName)
GO</pre> </p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>SQL Server: Optimize the Performance of TempDB</title>
		<link>https://www.dbrnd.com/2018/03/sql-server-optimize-the-performance-of-tempdb-add-multiple-data-files-store-ssd/</link>
					<comments>https://www.dbrnd.com/2018/03/sql-server-optimize-the-performance-of-tempdb-add-multiple-data-files-store-ssd/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Fri, 09 Mar 2018 16:16:11 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[Multiple data files]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tunning]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[Temp Table]]></category>
		<category><![CDATA[TempDB]]></category>
		<category><![CDATA[TempDB Performance]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=4256</guid>

					<description><![CDATA[<div><img width="679" height="452" src="https://www.dbrnd.com/wp-content/uploads/2017/12/SQL-RAM-Performance-679x452.jpg" class="attachment-post-image size-post-image wp-post-image" alt="SQL RAM Performance" decoding="async" loading="lazy" srcset="https://www.dbrnd.com/wp-content/uploads/2017/12/SQL-RAM-Performance-679x452.jpg 679w, https://www.dbrnd.com/wp-content/uploads/2017/12/SQL-RAM-Performance-850x566.jpg 850w, https://www.dbrnd.com/wp-content/uploads/2017/12/SQL-RAM-Performance.jpg 959w" sizes="auto, (max-width: 679px) 100vw, 679px" /></div>The Database Administrator must know something about the best configuration of TempDB. A general advice is, try to avoid the use of TempDB by creating temp tables. But TempDB also stores other information related to query execution, internal sort operation, overflow memory data. You should keep your eye open for TempDB otherwise it degrades the [&#8230;]]]></description>
										<content:encoded><![CDATA[<div><img width="679" height="452" src="https://www.dbrnd.com/wp-content/uploads/2017/12/SQL-RAM-Performance-679x452.jpg" class="attachment-post-image size-post-image wp-post-image" alt="SQL RAM Performance" decoding="async" loading="lazy" srcset="https://www.dbrnd.com/wp-content/uploads/2017/12/SQL-RAM-Performance-679x452.jpg 679w, https://www.dbrnd.com/wp-content/uploads/2017/12/SQL-RAM-Performance-850x566.jpg 850w, https://www.dbrnd.com/wp-content/uploads/2017/12/SQL-RAM-Performance.jpg 959w" sizes="auto, (max-width: 679px) 100vw, 679px" /></div><p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F03%2Fsql-server-optimize-the-performance-of-tempdb-add-multiple-data-files-store-ssd%2F&amp;linkname=SQL%20Server%3A%20Optimize%20the%20Performance%20of%20TempDB" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F03%2Fsql-server-optimize-the-performance-of-tempdb-add-multiple-data-files-store-ssd%2F&amp;linkname=SQL%20Server%3A%20Optimize%20the%20Performance%20of%20TempDB" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F03%2Fsql-server-optimize-the-performance-of-tempdb-add-multiple-data-files-store-ssd%2F&amp;linkname=SQL%20Server%3A%20Optimize%20the%20Performance%20of%20TempDB" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F03%2Fsql-server-optimize-the-performance-of-tempdb-add-multiple-data-files-store-ssd%2F&amp;linkname=SQL%20Server%3A%20Optimize%20the%20Performance%20of%20TempDB" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F03%2Fsql-server-optimize-the-performance-of-tempdb-add-multiple-data-files-store-ssd%2F&amp;linkname=SQL%20Server%3A%20Optimize%20the%20Performance%20of%20TempDB" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F03%2Fsql-server-optimize-the-performance-of-tempdb-add-multiple-data-files-store-ssd%2F&amp;linkname=SQL%20Server%3A%20Optimize%20the%20Performance%20of%20TempDB" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F03%2Fsql-server-optimize-the-performance-of-tempdb-add-multiple-data-files-store-ssd%2F&#038;title=SQL%20Server%3A%20Optimize%20the%20Performance%20of%20TempDB" data-a2a-url="https://www.dbrnd.com/2018/03/sql-server-optimize-the-performance-of-tempdb-add-multiple-data-files-store-ssd/" data-a2a-title="SQL Server: Optimize the Performance of TempDB"></a></p><p>The Database Administrator must know something about the best configuration of TempDB.<br />
A general advice is, try to avoid the use of TempDB by creating temp tables.</p>
<p>But TempDB also stores other information related to query execution, internal sort operation, overflow memory data.</p>
<p>You should keep your eye open for TempDB otherwise it degrades the overall performance.</p>
<blockquote class="wp-embedded-content" data-secret="BVUgm0ikvW"><p><a href="https://www.dbrnd.com/2016/02/sql-server-the-tempdb-is-full-shrink-it-or-move-it/">SQL Server: The TempDB is Full, Shrink it or Move it</a></p></blockquote>
<p><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/02/sql-server-the-tempdb-is-full-shrink-it-or-move-it/embed/#?secret=BVUgm0ikvW" data-secret="BVUgm0ikvW" width="600" height="338" title="&#8220;SQL Server: The TempDB is Full, Shrink it or Move it&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<p>Sharing few tips to improve the TempDB performance:</p>
<p><strong>Try to keep TempDB in local drive:</strong></p>
<blockquote><p>You should store TempDB in your local SSD drive instead of the shared network drive. This introduced by SQL Server 2012.</p></blockquote>
<blockquote><p>If you store other databases in shared network drive and TempDB in local drive, It creates a separate path for IO which divides the traffic and improves the performance.</p></blockquote>
<p><strong>Should configure multiple DATA Files:</strong></p>
<blockquote><p>You should create more data files equal to 1/2 or 1/4 the physical CPUs.</p></blockquote>
<blockquote><p>Once you have attached different data files to it, it stripped the files and performed the parallel operations.<br />
Now It has its own PFS, GAM, and SGAM pages, so it spreads the writing process which improves the writing performance.</p></blockquote>
<p><strong>Few other tips:</strong></p>
<ul>
<li>Set the recovery model of tempdb to SIMPLE.</li>
<li>Allow for tempdb files to automatically grow as required.</li>
<li>Set preallocate space for all tempdb files and it prevents tempdb from expanding too frequently.</li>
<li>Make each data file the same size.</li>
</ul>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2018/03/sql-server-optimize-the-performance-of-tempdb-add-multiple-data-files-store-ssd/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>SQL Server Interview: Difference between Sequence Object and Identity Column</title>
		<link>https://www.dbrnd.com/2018/03/sql-server-interview-difference-between-sequence-object-and-identity-column/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Thu, 08 Mar 2018 16:16:34 +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[IDENT_CURRENT]]></category>
		<category><![CDATA[Identity Column]]></category>
		<category><![CDATA[SCOPE_IDENTITY]]></category>
		<category><![CDATA[Sequence object]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server 2012]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tunning]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=4287</guid>

					<description><![CDATA[This is a common interview question for SQL Server Database Developer. SQL Database Developer must prepare for this. Sequence and identity, both used to generate an auto number, but the major difference is Identity is a table dependant and Sequence is independent of a table. A Sequence Object introduced in SQL Server 2012 and Identity [&#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%2F03%2Fsql-server-interview-difference-between-sequence-object-and-identity-column%2F&amp;linkname=SQL%20Server%20Interview%3A%20Difference%20between%20Sequence%20Object%20and%20Identity%20Column" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F03%2Fsql-server-interview-difference-between-sequence-object-and-identity-column%2F&amp;linkname=SQL%20Server%20Interview%3A%20Difference%20between%20Sequence%20Object%20and%20Identity%20Column" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F03%2Fsql-server-interview-difference-between-sequence-object-and-identity-column%2F&amp;linkname=SQL%20Server%20Interview%3A%20Difference%20between%20Sequence%20Object%20and%20Identity%20Column" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F03%2Fsql-server-interview-difference-between-sequence-object-and-identity-column%2F&amp;linkname=SQL%20Server%20Interview%3A%20Difference%20between%20Sequence%20Object%20and%20Identity%20Column" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F03%2Fsql-server-interview-difference-between-sequence-object-and-identity-column%2F&amp;linkname=SQL%20Server%20Interview%3A%20Difference%20between%20Sequence%20Object%20and%20Identity%20Column" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F03%2Fsql-server-interview-difference-between-sequence-object-and-identity-column%2F&amp;linkname=SQL%20Server%20Interview%3A%20Difference%20between%20Sequence%20Object%20and%20Identity%20Column" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F03%2Fsql-server-interview-difference-between-sequence-object-and-identity-column%2F&#038;title=SQL%20Server%20Interview%3A%20Difference%20between%20Sequence%20Object%20and%20Identity%20Column" data-a2a-url="https://www.dbrnd.com/2018/03/sql-server-interview-difference-between-sequence-object-and-identity-column/" data-a2a-title="SQL Server Interview: Difference between Sequence Object and Identity Column"></a></p><p>This is a common interview question for SQL Server Database Developer. SQL Database Developer must prepare for this.</p>
<p>Sequence and identity, both used to generate an auto number, but the major difference is Identity is a table dependant and Sequence is independent of a table.</p>
<blockquote><p>A Sequence Object introduced in SQL Server 2012 and Identity column introduced in SQL Server 6.0.</p></blockquote>
<blockquote><p>A Sequence is a User defined object and Identity column is a table property. </p></blockquote>
<blockquote><p> The same Sequence object can use with the multiple tables. The same Identity column cannot use with multiple tables, we can define identity column on each table individually. </p></blockquote>
<blockquote><p>If you define the same Sequence Object to multiple tables, it generates the sequence number database-wide and maintains a unique sequence number across the multiple tables. An Identity column generates a unique number at table only.</p></blockquote>
<blockquote><p>Sequence syntax (Start with 1 and Increment by 1):</p>
<pre class="crayon-plain-tag">CREATE SEQUENCE
  dbo.Sequence_Name AS INT
 START WITH 1
 INCREMENT BY 1
GO</pre> </p>
<p>Identity syntax (Start with 1 and Increment by 1):</p>
<pre class="crayon-plain-tag">CREATE TABLE dbo.Table_Name
( Id INT IDENTITY(1,1),
  Name VARCHAR(50) )
GO</pre>
</p></blockquote>
<blockquote><p>Check the next value of Sequence object:</p>
<pre class="crayon-plain-tag">SELECT (NEXT VALUE FOR dbo.Sequence_Name) AS SeqNextValue</pre> </p>
<p>Check the next value of Identity Column:</p>
<pre class="crayon-plain-tag">SELECT SCOPE_IDENTITY()</pre>
(write after use of Identity column)
</p></blockquote>
<blockquote><p>
Check the current value of Sequence Object:</p>
<pre class="crayon-plain-tag">SELECT Current_Value 
FROM Sys.Sequences 
WHERE name='Sequence_Name'</pre> </p>
<p>Check the current value of Identity Column:</p>
<pre class="crayon-plain-tag">SELECT IDENT_CURRENT('Table_Name') 
 AS 'IdentityCurrentValue'</pre>
</p></blockquote>
<blockquote><p>You can modify a Sequence object using ALTER Statement.</p>
<pre class="crayon-plain-tag">ALTER SEQUENCE dbo.Sequence_Name
RESTART WITH 100
INCREMENT BY 5
GO</pre> </p>
<p>You can only reset the value of an Identity column using DBCC CHECKIDENT().</p>
<pre class="crayon-plain-tag">DBCC CHECKIDENT('Table_Name', RESEED,100)</pre>
</p></blockquote>
<blockquote><p>In Sequence New values can be generated in an UPDATE statement, but in Identity new value cannot be generated in an UPDATE statement.</p></blockquote>
<blockquote><p>You can define a maximum value for Sequence Object (Using MAXVALUE). You cannot provide a maximum value to Identity Column.</p></blockquote>
<blockquote><p>Once your Sequence object reached to MAXVALUE, you can also define a CYCLE option to restart it from the beginning. You cannot restart an Identity column value.</p></blockquote>
<blockquote><p>You can also enable data CACHE for a Sequence Object. You cannot enable data CACHE for an Identity Column and it uses table related data cache. </p></blockquote>
<blockquote><p>A User must require an access permission for Sequence Object. For Identity column, User requires only table related permissions. </p></blockquote>
<blockquote><p>Performance wise, Identity column is 3x faster than Sequence object.</p></blockquote>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
