Getting Started with Adobe After Effects - Part 6: Motion Blur
A collection of quick technology learning tips from what people around you learn every day

bcp command for bulk copying data in sql

Nov 14 2011 9:41AM by RKA   

Recently read that to bulk copy data in sql, we can use bcp command. Below is a small example which copies data from one table to another.

It initially copies data to a bcp file from the original table. Then copy it to the destination table from the file. The sql query can also be written in a view and retrieved from there.

DECLARE
      @FileName varchar(50)
    , @bcpCommandfirst varchar(2000)
    , @bcpCommandsecond varchar(2000)

SET @FileName = 'd:\bcptest\sitetest.bcp'

SET @bcpCommandfirst  = 'bcp "SELECT sitenavigationid, linktext, linkurl, ParentSiteNavigationId FROM mydb..sitenavigation" queryout "' 

SET @bcpCommandfirst  = @bcpCommandfirst + @FileName + '" -U sa -P pass -c '

SET @bcpCommandsecond = 'bcp "mydb..sitenavigationcopy3" in "'+ @FileName + '" -U sa -P pass -c '

PRINT @bcpCommandfirst
PRINT @bcpCommandsecond

EXEC master..xp_cmdshell @bcpCommandfirst
EXEC master..xp_cmdshell @bcpCommandsecond

select * from dbo.[sitenavigation]
select * from dbo.[sitenavigationcopy3]

Read More..   [8 clicks]

Published under: SQL Server Tips ·  ·  ·  · 


RKA
91 · 2% · 598
6
 
4
 
 
0
Incorrect
 
0
Interesting
 
0
Forgotten



Submit

1  Comments  

  • Еxcellent solution since sql 2000, especially, if must be sent data to another department with a narrow channel of communication on the disk for example :) Yes, there were times ...

    commented on Nov 28 2011 3:47PM
    Vladimir
    989 · 0% · 26

Your Comment


Sign Up or Login to post a comment.

"bcp command for bulk copying data in sql" rated 5 out of 5 by 6 readers
bcp command for bulk copying data in sql , 5.0 out of 5 based on 6 ratings
    Copyright © Rivera Informatic Private Ltd Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising      [ZULU1097]