Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Administration (2000)
 BCP in some columns only - Problem!

Author  Topic 

sql_er
Constraint Violating Yak Guru

267 Posts

Posted - 2008-03-18 : 14:09:22
Guys,

I have a table with the following structure:

CREATE TABLE [dbo].[CTA] (
[CID] [int] NOT NULL ,
[AID] [int] NOT NULL ,
[NumOcc] [int] NULL ,
[Score] [int] NULL ,
[UID] [int] IDENTITY (1, 1) NOT NULL
) ON [Data1]
GO

It has 2 million records.

I want to BCP data out, all columns EXCEPT UID, clear out the table, change it to the structure below [i.e. start identity from MIN_INT] and BCP 4 columns in, letting the UID fill up by itself:

CREATE TABLE [dbo].[CTA] (
[CID] [int] NOT NULL ,
[AID] [int] NOT NULL ,
[NumOcc] [int] NULL ,
[Score] [int] NULL ,
[UID] [int] IDENTITY (-2147483647, 1) NOT NULL
) ON [Data1]
GO

I was able to BCP out the data successfully using the following command:

bcp "SELECT CID, AID, NumOcc, Score FROM DB.dbo.CTA WITH

(NOLOCK)" queryout c:\temp\CTA.bcp -n -S SQLCLUSTER03\NM -Uusername -Ppassword

I am having problem to BCP the data in though. Below is the command I used:

bcp DB.dbo.CTA in c:\temp\CTA.bcp -f C:\Temp\cta.fmt -S SQLCLUSTER03\NM -Uusername -Ppassword

and cta.fmt has the following structure:

8.0
4
1 SQLINT 0 12 "" 1 CID ""
2 SQLINT 0 12 "" 2 AID ""
3 SQLINT 0 12 "" 3 NumOcc ""
4 SQLINT 0 12 "" 4 Score ""

Although all the data is imported, it seems that the data is not correct. As if it was shifted. The only thing I can think of is that because the table itself has 5 columns [including UID], but I am only inserting into 4, this is the result. However, I thought that the format file would resolve that issue.


Please advise.
Thank a lot!



   

- Advertisement -