<?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>XP_CMDSHELL &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/xp_cmdshell/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, 30 Apr 2018 05:24:04 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.5</generator>
	<item>
		<title>SQL Server: Using xp_cmdshell, Read the data of Text File</title>
		<link>https://www.dbrnd.com/2018/05/sql-server-using-xp_cmdshell-read-the-data-of-text-file/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Wed, 02 May 2018 16:16:32 +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[export data to file]]></category>
		<category><![CDATA[Read data from file]]></category>
		<category><![CDATA[save data in file]]></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>
		<category><![CDATA[XP_CMDSHELL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=7519</guid>

					<description><![CDATA[In this post, I am sharing the demonstration on how to read the data from the file to SQL Server. Using xp_cmdshell windows command shell stored procedure, we can do data operation in the windows file directories. I also shared an article on how to export SQL Server table data into text file. SQL Server: [&#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%2F05%2Fsql-server-using-xp_cmdshell-read-the-data-of-text-file%2F&amp;linkname=SQL%20Server%3A%20Using%20xp_cmdshell%2C%20Read%20the%20data%20of%20Text%20File" 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%2F05%2Fsql-server-using-xp_cmdshell-read-the-data-of-text-file%2F&amp;linkname=SQL%20Server%3A%20Using%20xp_cmdshell%2C%20Read%20the%20data%20of%20Text%20File" 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%2F05%2Fsql-server-using-xp_cmdshell-read-the-data-of-text-file%2F&amp;linkname=SQL%20Server%3A%20Using%20xp_cmdshell%2C%20Read%20the%20data%20of%20Text%20File" 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%2F05%2Fsql-server-using-xp_cmdshell-read-the-data-of-text-file%2F&amp;linkname=SQL%20Server%3A%20Using%20xp_cmdshell%2C%20Read%20the%20data%20of%20Text%20File" 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%2F05%2Fsql-server-using-xp_cmdshell-read-the-data-of-text-file%2F&amp;linkname=SQL%20Server%3A%20Using%20xp_cmdshell%2C%20Read%20the%20data%20of%20Text%20File" 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%2F05%2Fsql-server-using-xp_cmdshell-read-the-data-of-text-file%2F&amp;linkname=SQL%20Server%3A%20Using%20xp_cmdshell%2C%20Read%20the%20data%20of%20Text%20File" 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%2F05%2Fsql-server-using-xp_cmdshell-read-the-data-of-text-file%2F&#038;title=SQL%20Server%3A%20Using%20xp_cmdshell%2C%20Read%20the%20data%20of%20Text%20File" data-a2a-url="https://www.dbrnd.com/2018/05/sql-server-using-xp_cmdshell-read-the-data-of-text-file/" data-a2a-title="SQL Server: Using xp_cmdshell, Read the data of Text File"></a></p><p>In this post, I am sharing the demonstration on how to read the data from the file to SQL Server. </p>
<p>Using xp_cmdshell windows command shell stored procedure, we can do data operation in the windows file directories.<br />
I also shared an article on how to export SQL Server table data into text file. </p>
<blockquote class="wp-embedded-content" data-secret="0QhA85yOvp"><p><a href="https://www.dbrnd.com/2017/03/sql-server-xp_cmdshell-and-bcp-to-export-table-data-in-a-text-file-data-migration/">SQL Server: xp_cmdshell and BCP to export table data in a Text File</a></p></blockquote>
<p><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2017/03/sql-server-xp_cmdshell-and-bcp-to-export-table-data-in-a-text-file-data-migration/embed/#?secret=0QhA85yOvp" data-secret="0QhA85yOvp" width="600" height="338" title="&#8220;SQL Server: xp_cmdshell and BCP to export table data in a Text File&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<p><strong>Enable xp_cmdshell:</strong></p>
<pre class="crayon-plain-tag">USE master;
GO
sp_CONFIGURE 'show advanced', 1
GO
RECONFIGURE
GO
sp_CONFIGURE 'xp_cmdshell', 1
GO
RECONFIGURE
GO</pre> </p>
<p><strong>Read the data from the file: </strong><br />
I created a text file in &#8216;D:\dbrnd.txt&#8217; location. My file contains &#8220;Database Research &#038; Development&#8221;.</p>
<pre class="crayon-plain-tag">DECLARE @Command VARCHAR(255)
DECLARE @Filepath VARCHAR(255)

SELECT @Filepath = ISNULL(@Filepath,'D:\dbrnd.txt') 
PRINT 'Path: ' + @Filepath

CREATE TABLE #tbl_ReadFile(filerecord VARCHAR(MAX))

IF @Filepath IS NOT NULL AND LEN(@Filepath) &gt; 10
BEGIN
	SELECT @Command = 'type ' + @Filepath
	INSERT INTO [dbo].[#tbl_ReadFile] 
	EXEC master.dbo.xp_cmdshell @Command
END</pre> </p>
<p><strong>Result:</strong></p>
<pre class="crayon-plain-tag">SELECT *FROM #tbl_ReadFile

filerecord
----------------------------------
Database Research &amp; Development</pre> </p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>SQL Server: xp_cmdshell and BCP to export table data in a Text File</title>
		<link>https://www.dbrnd.com/2017/03/sql-server-xp_cmdshell-and-bcp-to-export-table-data-in-a-text-file-data-migration/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Thu, 23 Mar 2017 16:16:22 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[BCP Command]]></category>
		<category><![CDATA[CSV File]]></category>
		<category><![CDATA[data migration]]></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[Text file]]></category>
		<category><![CDATA[TSQL]]></category>
		<category><![CDATA[XP_CMDSHELL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=4803</guid>

					<description><![CDATA[In this post, I am sharing a kind of utility article which you can use to export your records or data from SQL Server Database to Windows Text File. Let me share, where I am using this. I am monitoring the performance of a few critical stored procedures by logging in line important messages. Later, [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F03%2Fsql-server-xp_cmdshell-and-bcp-to-export-table-data-in-a-text-file-data-migration%2F&amp;linkname=SQL%20Server%3A%20xp_cmdshell%20and%20BCP%20to%20export%20table%20data%20in%20a%20Text%20File" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F03%2Fsql-server-xp_cmdshell-and-bcp-to-export-table-data-in-a-text-file-data-migration%2F&amp;linkname=SQL%20Server%3A%20xp_cmdshell%20and%20BCP%20to%20export%20table%20data%20in%20a%20Text%20File" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F03%2Fsql-server-xp_cmdshell-and-bcp-to-export-table-data-in-a-text-file-data-migration%2F&amp;linkname=SQL%20Server%3A%20xp_cmdshell%20and%20BCP%20to%20export%20table%20data%20in%20a%20Text%20File" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F03%2Fsql-server-xp_cmdshell-and-bcp-to-export-table-data-in-a-text-file-data-migration%2F&amp;linkname=SQL%20Server%3A%20xp_cmdshell%20and%20BCP%20to%20export%20table%20data%20in%20a%20Text%20File" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F03%2Fsql-server-xp_cmdshell-and-bcp-to-export-table-data-in-a-text-file-data-migration%2F&amp;linkname=SQL%20Server%3A%20xp_cmdshell%20and%20BCP%20to%20export%20table%20data%20in%20a%20Text%20File" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F03%2Fsql-server-xp_cmdshell-and-bcp-to-export-table-data-in-a-text-file-data-migration%2F&amp;linkname=SQL%20Server%3A%20xp_cmdshell%20and%20BCP%20to%20export%20table%20data%20in%20a%20Text%20File" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F03%2Fsql-server-xp_cmdshell-and-bcp-to-export-table-data-in-a-text-file-data-migration%2F&#038;title=SQL%20Server%3A%20xp_cmdshell%20and%20BCP%20to%20export%20table%20data%20in%20a%20Text%20File" data-a2a-url="https://www.dbrnd.com/2017/03/sql-server-xp_cmdshell-and-bcp-to-export-table-data-in-a-text-file-data-migration/" data-a2a-title="SQL Server: xp_cmdshell and BCP to export table data in a Text File"></a></p><p>In this post, I am sharing a kind of utility article which you can use to export your records or data from SQL Server Database to Windows Text File.</p>
<blockquote><p>Let me share, where I am using this. I am monitoring the performance of a few critical stored procedures by logging in line important messages.</p>
<p>Later, I am saving this details into a text file and sending that text file as an email attachment. We can also directly send table data as an email body, but we require into files for other tools also.</p></blockquote>
<p>You can use xp_cmdshell and BCP command to export your data from SQL Server to Text File.<br />
If you are getting an error like below, enable xp_cmdshell. You can use below reference article to enable xp_cmdshell.</p><pre class="crayon-plain-tag">Msg 15281, Level 16, State 1, Procedure xp_cmdshell, Line 1
SQL Server blocked access to procedure 'sys.xp_cmdshell' of component 'xp_cmdshell' because this component is turned off as part of the security configuration for this server. 
A system administrator can enable the use of 'xp_cmdshell' by using sp_configure. For more information about enabling 'xp_cmdshell', search for 'xp_cmdshell' in SQL Server Books Online.</pre><p>
<blockquote class="wp-embedded-content" data-secret="bs4P15yS1H"><p><a href="https://www.dbrnd.com/2015/11/sql-server-script-to-enable-and-disable-xp_cmdshell-configuration/">SQL Server: Script to Enable and Disable XP_CMDSHELL Configuration</a></p></blockquote>
<p><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2015/11/sql-server-script-to-enable-and-disable-xp_cmdshell-configuration/embed/#?secret=bs4P15yS1H" data-secret="bs4P15yS1H" width="600" height="338" title="&#8220;SQL Server: Script to Enable and Disable XP_CMDSHELL Configuration&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<p><strong>Create a table with sample data:</strong></p><pre class="crayon-plain-tag">CREATE TABLE tbl_Students
(
	Rno INT PRIMARY KEY
	,STudName VARCHAR(20)
	,ClassName CHAR(1)
)
GO

INSERT INTO tbl_Students 
VALUES 
(1,'Anvesh','A'),(2,'Neevan','B'),(3,'Toby','C')
,(5,'Roy','A'),(4,'Jenny','B'),(6,'Kaviy','C')
,(7,'Martin','A'),(8,'Laxmi','B'),(9,'Nion','C')
GO</pre><p>
<strong>Execute xp_cmdshell to export data in text file:</strong></p><pre class="crayon-plain-tag">EXEC xp_cmdshell 'bcp "SELECT * FROM dbo.tbl_Students" queryout "C:\Test\StudentData.txt" -T -c -t,'</pre><p>
<strong><img fetchpriority="high" decoding="async" class="alignnone wp-image-4807 size-full" title="SQL Server Export Data In Text File" src="https://www.dbrnd.com/wp-content/uploads/2017/03/SQLServerExportDataInTextFile.png" alt="SQL Server Export Data In Text File" width="403" height="165" srcset="https://www.dbrnd.com/wp-content/uploads/2017/03/SQLServerExportDataInTextFile.png 403w, https://www.dbrnd.com/wp-content/uploads/2017/03/SQLServerExportDataInTextFile-300x123.png 300w, https://www.dbrnd.com/wp-content/uploads/2017/03/SQLServerExportDataInTextFile-150x61.png 150w" sizes="(max-width: 403px) 100vw, 403px" /></strong></p>
<p><strong>Check the text file:</strong></p>
<p><img loading="lazy" decoding="async" class="alignnone wp-image-4806 size-full" title="SQL Server Export Data Result In Text" src="https://www.dbrnd.com/wp-content/uploads/2017/03/SQLServerExportDataResultInText.png" alt="SQL Server Export Data Result In Text" width="407" height="240" srcset="https://www.dbrnd.com/wp-content/uploads/2017/03/SQLServerExportDataResultInText.png 407w, https://www.dbrnd.com/wp-content/uploads/2017/03/SQLServerExportDataResultInText-300x177.png 300w, https://www.dbrnd.com/wp-content/uploads/2017/03/SQLServerExportDataResultInText-150x88.png 150w" sizes="auto, (max-width: 407px) 100vw, 407px" /></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>SQL Server: Database Security Interview Questions and Answers  (Day-5)</title>
		<link>https://www.dbrnd.com/2016/07/sql-server-database-security-interview-questions-and-answers-sql-audit-xp_cmdshell-sa-login-grant-deny-revoke-day-5/</link>
					<comments>https://www.dbrnd.com/2016/07/sql-server-database-security-interview-questions-and-answers-sql-audit-xp_cmdshell-sa-login-grant-deny-revoke-day-5/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Fri, 22 Jul 2016 14:06:57 +0000</pubDate>
				<category><![CDATA[SQL Server Interview]]></category>
		<category><![CDATA[answers]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[database security]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[deny]]></category>
		<category><![CDATA[GRANT]]></category>
		<category><![CDATA[interview]]></category>
		<category><![CDATA[questions]]></category>
		<category><![CDATA[REVOKE]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[sql server audit]]></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[XP_CMDSHELL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=3378</guid>

					<description><![CDATA[What do you know about the SQL Server Audit? SQL Server Audit is used to track and log events (not data change) occurring on the SQL Server. SQL Server uses extended events to help create an audit. The audit can be server level or database level. If you create an audit on a database table, [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F07%2Fsql-server-database-security-interview-questions-and-answers-sql-audit-xp_cmdshell-sa-login-grant-deny-revoke-day-5%2F&amp;linkname=SQL%20Server%3A%20Database%20Security%20Interview%20Questions%20and%20Answers%20%20%28Day-5%29" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F07%2Fsql-server-database-security-interview-questions-and-answers-sql-audit-xp_cmdshell-sa-login-grant-deny-revoke-day-5%2F&amp;linkname=SQL%20Server%3A%20Database%20Security%20Interview%20Questions%20and%20Answers%20%20%28Day-5%29" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F07%2Fsql-server-database-security-interview-questions-and-answers-sql-audit-xp_cmdshell-sa-login-grant-deny-revoke-day-5%2F&amp;linkname=SQL%20Server%3A%20Database%20Security%20Interview%20Questions%20and%20Answers%20%20%28Day-5%29" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F07%2Fsql-server-database-security-interview-questions-and-answers-sql-audit-xp_cmdshell-sa-login-grant-deny-revoke-day-5%2F&amp;linkname=SQL%20Server%3A%20Database%20Security%20Interview%20Questions%20and%20Answers%20%20%28Day-5%29" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F07%2Fsql-server-database-security-interview-questions-and-answers-sql-audit-xp_cmdshell-sa-login-grant-deny-revoke-day-5%2F&amp;linkname=SQL%20Server%3A%20Database%20Security%20Interview%20Questions%20and%20Answers%20%20%28Day-5%29" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F07%2Fsql-server-database-security-interview-questions-and-answers-sql-audit-xp_cmdshell-sa-login-grant-deny-revoke-day-5%2F&amp;linkname=SQL%20Server%3A%20Database%20Security%20Interview%20Questions%20and%20Answers%20%20%28Day-5%29" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F07%2Fsql-server-database-security-interview-questions-and-answers-sql-audit-xp_cmdshell-sa-login-grant-deny-revoke-day-5%2F&#038;title=SQL%20Server%3A%20Database%20Security%20Interview%20Questions%20and%20Answers%20%20%28Day-5%29" data-a2a-url="https://www.dbrnd.com/2016/07/sql-server-database-security-interview-questions-and-answers-sql-audit-xp_cmdshell-sa-login-grant-deny-revoke-day-5/" data-a2a-title="SQL Server: Database Security Interview Questions and Answers  (Day-5)"></a></p><p><strong>What do you know about the SQL Server Audit?</strong></p>
<blockquote><p>SQL Server Audit is used to track and log events (not data change) occurring on the SQL Server. SQL Server uses extended events to help create an audit. The audit can be server level or database level.</p>
<p>If you create an audit on a database table, SQL Server will only track the events that trigger the certain operations (SELECT/INSERT/UPDATE/DELETE) defined in the database audit specification.</p></blockquote>
<p><strong>What options are available to audit login activity?</strong></p>
<ul>
<li>Custom solution with your application to log all logins into a centralized table</li>
<li>Enable login auditing at the instance level in Management Studio</li>
<li>Execute Profiler to capture logins into the instance</li>
<li>Leverage a third party product</li>
</ul>
<p><strong>What is Audit in SQL Server?</strong></p>
<blockquote><p>Auditing an instance of the SQL Server Database Engine or an individual database involves tracking and logging events that occur on the Database Engine.</p></blockquote>
<p><strong>What is Server level Audit specification?</strong></p>
<blockquote><p>You can create one server audit specification per audit.</p>
<p>The server audit specification collects many server-level action groups raised by the Extended Events feature. You can include audit action groups in a server audit specification. Audit action groups are predefined groups of actions, which are atomic events occurring in the Database Engine.</p></blockquote>
<p><strong>What is Database level Audit specification?</strong></p>
<blockquote><p>You can create one database audit specification per SQL Server database per audit.</p>
<p>The database audit specification collects database-level audit actions raised by the Extended Events feature. You can add either audit action groups or audit events to a database audit specification.</p></blockquote>
<p><strong>Is it good to enable Audit only for SQL Server Login fails?</strong></p>
<blockquote><p>Yes:</p>
<p>Database administrators should enable login auditing feature of SQL Server on all instances which they manage. Once this feature is enabled SQL Server will write all the failed and successful login information in SQL Server Error Logs. It is always a best practice to auditing failed SQL Server logins.</p></blockquote>
<p><strong>Does SQL Server Audit require any additional permission?</strong></p>
<blockquote><p>Yes:</p>
<p>Each feature and command for SQL Server Audit has individual permission requirements.</p></blockquote>
<p><strong>Should we encrypt the SQL Server datatabase backups?</strong></p>
<blockquote><p>Yes:</p>
<p>We need to make sure the database backups are encrypted to avoid the misuse.</p></blockquote>
<p><strong>Why we should not use tha SA login for all the different SQL Server access?</strong></p>
<blockquote><p>Because, the sa login and password to all of your SQL Servers because auditing the sa login with a shared password is difficult without capturing the host name or some other personally identifiable data. We should migrate all SQL Server authentication to Windows based authentication.</p></blockquote>
<p><strong>Can I stop a System Admin from enabling SQL Server xp_cmdshell?</strong></p>
<blockquote><p>No:</p></blockquote>
<p><strong>T-SQL script to disable the SA login</strong></p><pre class="crayon-plain-tag">ALTER LOGIN sa DISABLE;</pre><p>
<strong>T-SQL script to rename the SQ login.</strong></p><pre class="crayon-plain-tag">ALTER LOGIN sa WITH NAME = [dbrnd_user];</pre><p>
<strong>Please do auto reset the SA password and disable it.</strong></p>
<blockquote><p>SQL Server has an undocumented system stored procedure named sp_SetAutoSAPasswordAndDisable. This procedure will do exactly as the name suggests: it will reset the password and then disable the &#8216;sa&#8217; login.</p></blockquote>
<pre class="crayon-plain-tag">EXEC sp_SetAutoSAPasswordAndDisable
GO</pre>
<strong>T-SQL script to find common passwords.</strong><br />
<pre class="crayon-plain-tag">SELECT name,type_desc,create_date,modify_date,password_hash 
FROM sys.sql_logins 
WHERE PWDCOMPARE('mssqltips',password_hash)=1;</pre>
<strong>T-SQL script to find blank passwords.</strong><br />
<pre class="crayon-plain-tag">SELECT name,type_desc,create_date,modify_date,password_hash 
FROM sys.sql_logins 
WHERE PWDCOMPARE('',password_hash)=1;</pre>
<strong>T-SQL script to find Passwords that are the same as the Login name.</strong><br />
<pre class="crayon-plain-tag">SELECT name,type_desc,create_date,modify_date,password_hash 
FROM sys.sql_logins 
WHERE PWDCOMPARE(name,password_hash)=1;</pre>
<strong>What is GRANT, DENY and REVOKE?</strong></p>
<blockquote><p>GRANT:gives a user permission to perform certain tasks on database objects.<br />
DENY:denies any access to a user to perform certain tasks on database objects.<br />
REVOKE:removes a grant or deny permission from a user on certain database objects.</p></blockquote>
<p><strong>Sample T-SQL scripts for GRANT, DENY and REVOKE.</strong><br />
<pre class="crayon-plain-tag">GRANT INSERT, UPDATE, SELECT ON Customers TO Joe, Mary;
DENY DELETE ON Customers to Joe, Mary;
REVOKE UPDATE ON Customers to Joe;</pre>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2016/07/sql-server-database-security-interview-questions-and-answers-sql-audit-xp_cmdshell-sa-login-grant-deny-revoke-day-5/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>SQL Server: Script to Enable and Disable XP_CMDSHELL Configuration</title>
		<link>https://www.dbrnd.com/2015/11/sql-server-script-to-enable-and-disable-xp_cmdshell-configuration/</link>
					<comments>https://www.dbrnd.com/2015/11/sql-server-script-to-enable-and-disable-xp_cmdshell-configuration/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Sat, 14 Nov 2015 16:08:29 +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 Tips and Tricks]]></category>
		<category><![CDATA[TSQL]]></category>
		<category><![CDATA[XP_CMDSHELL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=947</guid>

					<description><![CDATA[In this post, I am sharing a script to check, enable and disable XP_CMDSHELL in the SQL Server. This script is handy for those professionals, who are interested in using command line utilities with SQL Server. If you want to use command line tool, you should enable this XP_CMDSHELL configuration. First, Check XP_CMDSHELL is enabled [&#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%2F2015%2F11%2Fsql-server-script-to-enable-and-disable-xp_cmdshell-configuration%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20Enable%20and%20Disable%20XP_CMDSHELL%20Configuration" 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%2F2015%2F11%2Fsql-server-script-to-enable-and-disable-xp_cmdshell-configuration%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20Enable%20and%20Disable%20XP_CMDSHELL%20Configuration" 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%2F2015%2F11%2Fsql-server-script-to-enable-and-disable-xp_cmdshell-configuration%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20Enable%20and%20Disable%20XP_CMDSHELL%20Configuration" 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%2F2015%2F11%2Fsql-server-script-to-enable-and-disable-xp_cmdshell-configuration%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20Enable%20and%20Disable%20XP_CMDSHELL%20Configuration" 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%2F2015%2F11%2Fsql-server-script-to-enable-and-disable-xp_cmdshell-configuration%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20Enable%20and%20Disable%20XP_CMDSHELL%20Configuration" 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%2F2015%2F11%2Fsql-server-script-to-enable-and-disable-xp_cmdshell-configuration%2F&amp;linkname=SQL%20Server%3A%20Script%20to%20Enable%20and%20Disable%20XP_CMDSHELL%20Configuration" 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%2F2015%2F11%2Fsql-server-script-to-enable-and-disable-xp_cmdshell-configuration%2F&#038;title=SQL%20Server%3A%20Script%20to%20Enable%20and%20Disable%20XP_CMDSHELL%20Configuration" data-a2a-url="https://www.dbrnd.com/2015/11/sql-server-script-to-enable-and-disable-xp_cmdshell-configuration/" data-a2a-title="SQL Server: Script to Enable and Disable XP_CMDSHELL Configuration"></a></p><p>In this post, I am sharing a script to check, enable and disable XP_CMDSHELL in the SQL Server. </p>
<p>This script is handy for those professionals, who are interested in using command line utilities with SQL Server.</p>
<p>If you want to use command line tool, you should enable this XP_CMDSHELL configuration. </p>
<p><strong>First, Check XP_CMDSHELL is enabled on the server:</strong></p>
<pre class="crayon-plain-tag">SELECT CONVERT(INT, ISNULL(value, value_in_use)) AS ConfigValue
FROM sys.configurations
WHERE name = 'xp_cmdshell' ;</pre> </p>
<p><strong>Script to enable and disable XP_CMDSHELL:</strong></p>
<pre class="crayon-plain-tag">-- Enable advanced options to be changed.
EXEC SP_CONFIGURE 'show advanced options', 1
GO
RECONFIGURE
GO
-- Enable xp_cmdshell option.
EXEC SP_CONFIGURE N'xp_cmdshell', 1
GO
RECONFIGURE
GO
-- Disable xp_cmdshell option. 
EXEC SP_CONFIGURE 'xp_cmdshell', 0
GO
RECONFIGURE
GO
-- Disable advanced options to be changed.
EXEC SP_CONFIGURE 'show advanced options', 0
GO
RECONFIGURE
GO</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2015/11/sql-server-script-to-enable-and-disable-xp_cmdshell-configuration/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
	</channel>
</rss>
