Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How do you import/export data with BCP or Bulk Insert?

Posted on 2004-09-02
3
Medium Priority
?
568 Views
Last Modified: 2008-02-26
How do you import/export data with BCP or Bulk Insert?

I have always used DTS but for a very large file it does not seem to be the best option
0
Comment
Question by:robrodp
  • 2
3 Comments
 
LVL 11

Accepted Solution

by:
ram2098 earned 1500 total points
ID: 11970521
BULK INSERT is basically used to trasnfer the data from a file to SQL Server. Remember this is a SQL Command and you can execute this using query analyzer (or) Stored Procedure directly.

Syntax as follows:

BULK INSERT Northwind.dbo.[Order Details]
   FROM 'f:\orders\lineitem.tbl'
   WITH
      (
         FIELDTERMINATOR = '|',
         ROWTERMINATOR = '|\n'
      )


BCP ..you can use to copy the data from a file to SQL Server (or) to a file from a SQL database. But, this you need to execute this from a command prompt. (or) using xp_cmdshell from query analyzer (or) Stored Procedures.

bcp "Northwind.Jane Doe.Jane's Orders" out "Jane's Orders.txt" -c -q -U"Jane Doe" -P"go dba"

You can see SQL Books online for more details about the arguments
0
 
LVL 11

Expert Comment

by:ram2098
ID: 11970530
And one more thing to add...

If you have files with specific delimiters to transfer to SQL (or) Vice Versa, using BCP (or) BULK INSERT is much simpler.

If you have files with fixed length, you need to use format files to do the transfer using BCP.
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question