views:

125

answers:

2

I am running a bulk copy of two columns of a table from one server to another.

The table on the source side has about 8 columns, but I only need 2.

The table on the destination side has 2 columns (the two that I need, both are of type int)

Both databases are SQL Server 2005.

Here's my two bcp commands:

c:\> bcp "select c1, c2 from srcTable" queryout tableData.bcp -N -T -S srcServer
c:\> bcp destTable in tableData.bcp -N -T -S destServer

Why does this corrupt the data in the destination table? I should be getting nice, sequential integers, instead I get this:

c1          c2
586332      83014148
123128736   -105042384
-561616278  -309997736

What am I doing wrong?

+1  A: 

Got it.

The column definition must match exactly - including whether it is NULL or NOT NULL.

The source had:

srcTable (
c1 int not null (PK)
c2 int null
c3 datetime not null
c4 datetime null
...
)

The destination table had:

destTable (
c1 int not null (PK)
c2 int not null 
)

The NOT NULL on destTable.c2 was the bug.

It's been squashed now.

Jeff Meatball Yang
A: 

Sorry, I recently had the same problem. Do you know why it matters for bcp?

Elvy
I think that bcp uses some binary representation of the data instead of a more abstracted format. I'm not sure, but at least you should make sure your table definitions are EXACTLY the same on both servers.
Jeff Meatball Yang