Solved

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

Posted on 2004-09-02
3
521 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 500 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
 
LVL 1

Expert Comment

by:Parag_Gujarathi
ID: 11970568
0

Featured Post

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

Introduced in Microsoft SQL Server 2005, the Copy Database Wizard (http://msdn.microsoft.com/en-us/library/ms188664.aspx) is useful in copying databases and associated objects between SQL instances; therefore, it is a good migration and upgrade tool…
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now