<?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>data migration &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/data-migration/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, 08 Feb 2019 18:43:57 +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: 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: 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>
		<item>
		<title>PostgreSQL: Shell script to copy table data from one server to another server</title>
		<link>https://www.dbrnd.com/2017/03/postgresql-shell-script-to-copy-table-data-from-one-server-to-another-server-psql-copy-command-data-migration/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Thu, 02 Mar 2017 16:16:00 +0000</pubDate>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[PostgreSQL DBA Script]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[Bash shell script]]></category>
		<category><![CDATA[Copy command]]></category>
		<category><![CDATA[data migration]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[plpgsql]]></category>
		<category><![CDATA[Postgres Query]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[PostgreSQL Administrator]]></category>
		<category><![CDATA[PostgreSQL Error]]></category>
		<category><![CDATA[PostgreSQL Monitoring]]></category>
		<category><![CDATA[PostgreSQL Performance Tuning]]></category>
		<category><![CDATA[PostgreSQL Programming]]></category>
		<category><![CDATA[PostgreSQL Tips and Tricks]]></category>
		<category><![CDATA[psql]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=4672</guid>

					<description><![CDATA[Recently, I shared one article on PostgreSQL schemas migration. PostgreSQL: Script to copy Table Data from one Schema to another Schema The migration activities are very common for all DBAs. I found lots of different questions on migration exercises. In this post, I am sharing a Linux shell script to copy your table data from [&#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%2Fpostgresql-shell-script-to-copy-table-data-from-one-server-to-another-server-psql-copy-command-data-migration%2F&amp;linkname=PostgreSQL%3A%20Shell%20script%20to%20copy%20table%20data%20from%20one%20server%20to%20another%20server" 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%2Fpostgresql-shell-script-to-copy-table-data-from-one-server-to-another-server-psql-copy-command-data-migration%2F&amp;linkname=PostgreSQL%3A%20Shell%20script%20to%20copy%20table%20data%20from%20one%20server%20to%20another%20server" 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%2Fpostgresql-shell-script-to-copy-table-data-from-one-server-to-another-server-psql-copy-command-data-migration%2F&amp;linkname=PostgreSQL%3A%20Shell%20script%20to%20copy%20table%20data%20from%20one%20server%20to%20another%20server" 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%2Fpostgresql-shell-script-to-copy-table-data-from-one-server-to-another-server-psql-copy-command-data-migration%2F&amp;linkname=PostgreSQL%3A%20Shell%20script%20to%20copy%20table%20data%20from%20one%20server%20to%20another%20server" 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%2Fpostgresql-shell-script-to-copy-table-data-from-one-server-to-another-server-psql-copy-command-data-migration%2F&amp;linkname=PostgreSQL%3A%20Shell%20script%20to%20copy%20table%20data%20from%20one%20server%20to%20another%20server" 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%2Fpostgresql-shell-script-to-copy-table-data-from-one-server-to-another-server-psql-copy-command-data-migration%2F&amp;linkname=PostgreSQL%3A%20Shell%20script%20to%20copy%20table%20data%20from%20one%20server%20to%20another%20server" 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%2Fpostgresql-shell-script-to-copy-table-data-from-one-server-to-another-server-psql-copy-command-data-migration%2F&#038;title=PostgreSQL%3A%20Shell%20script%20to%20copy%20table%20data%20from%20one%20server%20to%20another%20server" data-a2a-url="https://www.dbrnd.com/2017/03/postgresql-shell-script-to-copy-table-data-from-one-server-to-another-server-psql-copy-command-data-migration/" data-a2a-title="PostgreSQL: Shell script to copy table data from one server to another server"></a></p><p>Recently, I shared one article on PostgreSQL schemas migration. </p>
<blockquote data-secret="dbPEectos8" class="wp-embedded-content"><p><a href="https://www.dbrnd.com/2017/02/postgresql-script-to-copy-schema-table-data-to-another-schema-table-migration/">PostgreSQL: Script to copy Table Data from one Schema to another Schema</a></p></blockquote>
<p><iframe loading="lazy" class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2017/02/postgresql-script-to-copy-schema-table-data-to-another-schema-table-migration/embed/#?secret=dbPEectos8" data-secret="dbPEectos8" width="600" height="338" title="&#8220;PostgreSQL: Script to copy Table Data from one Schema to another Schema&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<p>The migration activities are very common for all DBAs. I found lots of different questions on migration exercises.<br />
In this post, I am sharing a Linux shell script to copy your table data from one PostgreSQL Server to another PostgreSQL Server using psql command line. </p>
<blockquote><p>I am just migrating the data; please create a blank table at your destination/second database server. </p>
<p>This is a utility script. Further, you can modify the script for generic use something like by adding parameters for host_name, database_name, table_name and others</p></blockquote>
<p><strong>Linux Bash Shell Script for data migration between PostgreSQL Servers:</strong></p>
<pre class="crayon-plain-tag">#!/bin/bash
psql \
    -X \
    -U user_name \
    -h host_name1 \
    -d database_name \
    -c "\\copy tbl_Students to stdout" \
| \
psql \
    -X \
    -U user_name \
    -h host_name2 \
    -d database_name \
    -c "\\copy tbl_Students from stdin"</pre> </p>
<p><strong>You can also filter the column list something like below script:</strong></p>
<pre class="crayon-plain-tag">#!/bin/bash
psql \
    -X \
    -U user_name \
    -h host_name1 \
    -d database_name \
    -c "\\copy (SELECT Rno, Studname FROM tbl_Students) to stdout" \
| \
psql \
    -X \
    -U user_name \
    -h host_name2 \
    -d database_name \
    -c "\\copy tbl_Students from stdin"</pre> </p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>PostgreSQL: How to Disable or Enable Foreign Key Constraint of a Table</title>
		<link>https://www.dbrnd.com/2017/02/postgresql-how-to-disable-or-enable-foreign-key-constraint-of-a-table-data-migration-bulk-operation/</link>
					<comments>https://www.dbrnd.com/2017/02/postgresql-how-to-disable-or-enable-foreign-key-constraint-of-a-table-data-migration-bulk-operation/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Thu, 02 Feb 2017 16:16:49 +0000</pubDate>
				<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[bulk operation]]></category>
		<category><![CDATA[data migration]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[Disable Foreign Key Constraint]]></category>
		<category><![CDATA[Foreign Key constraint]]></category>
		<category><![CDATA[plpgsql]]></category>
		<category><![CDATA[Postgres Query]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[PostgreSQL Administrator]]></category>
		<category><![CDATA[PostgreSQL Error]]></category>
		<category><![CDATA[PostgreSQL Performance Tuning]]></category>
		<category><![CDATA[PostgreSQL Programming]]></category>
		<category><![CDATA[PostgreSQL Tips and Tricks]]></category>
		<category><![CDATA[trigger]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=3939</guid>

					<description><![CDATA[In this post, I am sharing one option to Disable / Enable the Foreign Key Constraint in PostgreSQL. During data migration and testing purpose, Database Developer requires to disable Foreign key constraint of a Table. Once you disable constraint, then later you might need to enable again, but during this exercise make sure that all [&#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%2F02%2Fpostgresql-how-to-disable-or-enable-foreign-key-constraint-of-a-table-data-migration-bulk-operation%2F&amp;linkname=PostgreSQL%3A%20How%20to%20Disable%20or%20Enable%20Foreign%20Key%20Constraint%20of%20a%20Table" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F02%2Fpostgresql-how-to-disable-or-enable-foreign-key-constraint-of-a-table-data-migration-bulk-operation%2F&amp;linkname=PostgreSQL%3A%20How%20to%20Disable%20or%20Enable%20Foreign%20Key%20Constraint%20of%20a%20Table" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F02%2Fpostgresql-how-to-disable-or-enable-foreign-key-constraint-of-a-table-data-migration-bulk-operation%2F&amp;linkname=PostgreSQL%3A%20How%20to%20Disable%20or%20Enable%20Foreign%20Key%20Constraint%20of%20a%20Table" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F02%2Fpostgresql-how-to-disable-or-enable-foreign-key-constraint-of-a-table-data-migration-bulk-operation%2F&amp;linkname=PostgreSQL%3A%20How%20to%20Disable%20or%20Enable%20Foreign%20Key%20Constraint%20of%20a%20Table" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F02%2Fpostgresql-how-to-disable-or-enable-foreign-key-constraint-of-a-table-data-migration-bulk-operation%2F&amp;linkname=PostgreSQL%3A%20How%20to%20Disable%20or%20Enable%20Foreign%20Key%20Constraint%20of%20a%20Table" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F02%2Fpostgresql-how-to-disable-or-enable-foreign-key-constraint-of-a-table-data-migration-bulk-operation%2F&amp;linkname=PostgreSQL%3A%20How%20to%20Disable%20or%20Enable%20Foreign%20Key%20Constraint%20of%20a%20Table" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F02%2Fpostgresql-how-to-disable-or-enable-foreign-key-constraint-of-a-table-data-migration-bulk-operation%2F&#038;title=PostgreSQL%3A%20How%20to%20Disable%20or%20Enable%20Foreign%20Key%20Constraint%20of%20a%20Table" data-a2a-url="https://www.dbrnd.com/2017/02/postgresql-how-to-disable-or-enable-foreign-key-constraint-of-a-table-data-migration-bulk-operation/" data-a2a-title="PostgreSQL: How to Disable or Enable Foreign Key Constraint of a Table"></a></p><p>In this post, I am sharing one option to Disable / Enable the Foreign Key Constraint in PostgreSQL.</p>
<blockquote><p>During data migration and testing purpose, Database Developer requires to disable Foreign key constraint of a Table.</p></blockquote>
<blockquote><p>Once you disable constraint, then later you might need to enable again, but during this exercise make sure that all your data changes are correct.</p></blockquote>
<blockquote><p>PostgreSQL does not provide any direct command or function to disable / enable the Foreign key constraints. </p></blockquote>
<blockquote><p>When you create any Foreign Key on the table, internally It creates a hidden trigger for check data integrity.<br />
You should enable/disable the trigger for achieving disable foreign key constraint.</p></blockquote>
<p><strong>Create a sample Student Master table:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE tbl_Students 
(
	StudID INTEGER PRIMARY KEY
	,StudName CHARACTER VARYING
	,StudClass CHAR(1)	
);</pre> </p>
<p><strong>Insert few sample records in Student Master table:</strong></p>
<pre class="crayon-plain-tag">INSERT INTO tbl_Students 
VALUES (1,'Anvesh','A')
,(2,'Neevan','B'),(3,'Jenny','C')
,(4,'Roy','C'),(5,'Martin','C');</pre> </p>
<p><strong>Create a sample Student Marks table:</strong></p>
<pre class="crayon-plain-tag">CREATE TABLE tbl_StudentMarks
(
	StudentMarkID INTEGER PRIMARY KEY
	,StudID INTEGER 
	,Sub1Mark SMALLINT
	,Sub2Mark SMALLINT
	,Sub3Mark SMALLINT	
	,CONSTRAINT fk_tbl_StudentMarks_StudID FOREIGN KEY (StudID) REFERENCES tbl_Students (StudID)
);</pre> </p>
<p><strong>Try to insert data with StudID which does not belong to Student Master table:</strong></p>
<pre class="crayon-plain-tag">INSERT INTO tbl_StudentMarks 
VALUES (1,6,50,60,90);</pre> </p>
<p><strong>You will get a below error message:</strong></p>
<pre class="crayon-plain-tag">ERROR:  insert or update on table "tbl_studentmarks" violates foreign key constraint "fk_tbl_studentmarks_studid"
DETAIL:  Key (studid)=(6) is not present in table "tbl_students".
********** Error **********</pre> </p>
<p><strong>Disable all hidden triggers of a Student Mark table:</strong></p>
<pre class="crayon-plain-tag">ALTER TABLE tbl_StudentMarks DISABLE TRIGGER ALL;</pre> </p>
<p><strong>Now Again, try to insert same record:</strong></p>
<pre class="crayon-plain-tag">INSERT INTO tbl_StudentMarks 
VALUES (1,6,50,60,90);</pre> </p>
<p><strong>Once you did with your task, please enable all trigger of a table:</strong></p>
<pre class="crayon-plain-tag">ALTER TABLE tbl_StudentMarks ENABLE TRIGGER ALL;</pre> </p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2017/02/postgresql-how-to-disable-or-enable-foreign-key-constraint-of-a-table-data-migration-bulk-operation/feed/</wfw:commentRss>
			<slash:comments>11</slash:comments>
		
		
			</item>
		<item>
		<title>MySQL: Understand Case Sensitivity parameters for Effective Migration (Case Sensitive or Case Insensitive)</title>
		<link>https://www.dbrnd.com/2016/11/mysql-understand-case-sensitivity-parameters-for-effective-migration-case-sensitive-or-case-insensitive/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Wed, 16 Nov 2016 18:12:50 +0000</pubDate>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[Case Insensitive]]></category>
		<category><![CDATA[case-sensitive]]></category>
		<category><![CDATA[data migration]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[lower_case_file_system]]></category>
		<category><![CDATA[lower_case_table_names]]></category>
		<category><![CDATA[MySQL Command]]></category>
		<category><![CDATA[MySQL Database Administrator]]></category>
		<category><![CDATA[MySQL Database Designing]]></category>
		<category><![CDATA[MySQL Database Programming]]></category>
		<category><![CDATA[MySQL Error]]></category>
		<category><![CDATA[MySQL Performance Tunning]]></category>
		<category><![CDATA[MySQL Query]]></category>
		<category><![CDATA[MySQL Tips and Tricks]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=3860</guid>

					<description><![CDATA[During the migration activity, most of the time we are facing issues related to Case Sensitivity. For example, In Windows Operating System, you cannot create two different directories like: &#8220;DBrnd.Com&#8221; and &#8220;dbrnd.com&#8221;. This both consider as same name in Windows Operating System, but In Linux Operating System, You can create both directories separately like: &#8220;DBrnd. [&#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%2F11%2Fmysql-understand-case-sensitivity-parameters-for-effective-migration-case-sensitive-or-case-insensitive%2F&amp;linkname=MySQL%3A%20Understand%20Case%20Sensitivity%20parameters%20for%20Effective%20Migration%20%28Case%20Sensitive%20or%20Case%20Insensitive%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%2F11%2Fmysql-understand-case-sensitivity-parameters-for-effective-migration-case-sensitive-or-case-insensitive%2F&amp;linkname=MySQL%3A%20Understand%20Case%20Sensitivity%20parameters%20for%20Effective%20Migration%20%28Case%20Sensitive%20or%20Case%20Insensitive%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%2F11%2Fmysql-understand-case-sensitivity-parameters-for-effective-migration-case-sensitive-or-case-insensitive%2F&amp;linkname=MySQL%3A%20Understand%20Case%20Sensitivity%20parameters%20for%20Effective%20Migration%20%28Case%20Sensitive%20or%20Case%20Insensitive%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%2F11%2Fmysql-understand-case-sensitivity-parameters-for-effective-migration-case-sensitive-or-case-insensitive%2F&amp;linkname=MySQL%3A%20Understand%20Case%20Sensitivity%20parameters%20for%20Effective%20Migration%20%28Case%20Sensitive%20or%20Case%20Insensitive%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%2F11%2Fmysql-understand-case-sensitivity-parameters-for-effective-migration-case-sensitive-or-case-insensitive%2F&amp;linkname=MySQL%3A%20Understand%20Case%20Sensitivity%20parameters%20for%20Effective%20Migration%20%28Case%20Sensitive%20or%20Case%20Insensitive%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%2F11%2Fmysql-understand-case-sensitivity-parameters-for-effective-migration-case-sensitive-or-case-insensitive%2F&amp;linkname=MySQL%3A%20Understand%20Case%20Sensitivity%20parameters%20for%20Effective%20Migration%20%28Case%20Sensitive%20or%20Case%20Insensitive%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%2F11%2Fmysql-understand-case-sensitivity-parameters-for-effective-migration-case-sensitive-or-case-insensitive%2F&#038;title=MySQL%3A%20Understand%20Case%20Sensitivity%20parameters%20for%20Effective%20Migration%20%28Case%20Sensitive%20or%20Case%20Insensitive%29" data-a2a-url="https://www.dbrnd.com/2016/11/mysql-understand-case-sensitivity-parameters-for-effective-migration-case-sensitive-or-case-insensitive/" data-a2a-title="MySQL: Understand Case Sensitivity parameters for Effective Migration (Case Sensitive or Case Insensitive)"></a></p><p>During the migration activity, most of the time we are facing issues related to Case Sensitivity.<br />
For example, </p>
<blockquote><p>In Windows Operating System, you cannot create two different directories like: &#8220;DBrnd.Com&#8221; and &#8220;dbrnd.com&#8221;. This both consider as same name in Windows Operating System, but In Linux Operating System, You can create both directories separately like: &#8220;DBrnd. Com&#8221; and &#8220;dbrnd.com&#8221;.</p></blockquote>
<blockquote><p>When we are migrating MySQL Database between two different Operating Systems, we should also take care about the name of Database files and folders.</p></blockquote>
<p><strong>There are mainly two MySQL Server parameters lower_case_file_system and lower_case_table_names.</strong></p>
<blockquote><p>A lower_case_file_system parameter ensures about case sensitivity of file names on the file system where the data directory is located.<br />
A lower_case_file_system OFF means file names are Case Sensitive, and ON means file names are Case Insensitive.</p></blockquote>
<blockquote><p>A lower_case_table_names parameters ensure about case sensitivity of table names.<br />
<strong>If lower_case_table_names = 0,</strong> Table name stored as specified, but comparisons are Case Sensitive.<br />
<strong>If lower_case_table_names = 1,</strong> Table name stored in lower case and comparisons are not Case Sensitive.<br />
<strong>If lower_case_table_names = 2,</strong> Table name stored as specified, but comparisons are in Lowercase.</p></blockquote>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
