<?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>Text file &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/text-file/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>Fri, 10 Mar 2017 22:37:14 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.4</generator>
	<item>
		<title>SQL Server: 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 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="(max-width: 407px) 100vw, 407px" /></p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
