SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


bcp


Author
Message
john.priest
john.priest
SSC-Enthusiastic
SSC-Enthusiastic (117 reputation)SSC-Enthusiastic (117 reputation)SSC-Enthusiastic (117 reputation)SSC-Enthusiastic (117 reputation)SSC-Enthusiastic (117 reputation)SSC-Enthusiastic (117 reputation)SSC-Enthusiastic (117 reputation)SSC-Enthusiastic (117 reputation)

Group: General Forum Members
Points: 117 Visits: 19
I am trying to bcp some data from one database to another via bcp (i know i can use other methods but is tarted using this as a self-training mechanism).

An issue comes when I try to import the data into the new database table. The issue concerns the fact that the table(s) have a column called key.

If I try to import the data I get the following error message
SQLState = 37000, NativeError = 156
Error = [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near the keyword 'key'.

I have several hundred tables with a column called key. Is there any way to overcome this issue without re-naming every key column to skey (or something).

Cheers
JP
Jeff Moden
Jeff Moden
SSC Guru
SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)SSC Guru (85K reputation)

Group: General Forum Members
Points: 85867 Visits: 41091
Can we see the BCP command, please, John? Be sure to remember to not include your server password. Thanks.

--Jeff Moden

RBAR is pronounced ree-bar and is a Modenism for Row-By-Agonizing-Row.
First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column.
If you think its expensive to hire a professional to do the job, wait until you hire an amateur. -- Red Adair

Helpful Links:
How to post code problems
How to post performance problems
Forum FAQs
john.priest
john.priest
SSC-Enthusiastic
SSC-Enthusiastic (117 reputation)SSC-Enthusiastic (117 reputation)SSC-Enthusiastic (117 reputation)SSC-Enthusiastic (117 reputation)SSC-Enthusiastic (117 reputation)SSC-Enthusiastic (117 reputation)SSC-Enthusiastic (117 reputation)SSC-Enthusiastic (117 reputation)

Group: General Forum Members
Points: 117 Visits: 19
bcp command:
"C:\PROGRAM FILES\MIcrosoft SQL Server\80\Tools\Binn\bcp" ie_master.dbo.D_BillTypes out Y:\bcptest\D_BillTypes.txt -S******** -Uds_user -P******* -fY:\bcptest\D_BillTypes.fmt

table definition:
USE ie_master
go
CREATE TABLE dbo.D_BillType
(
BTC_BILL_TYPE_CODE char(3) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
BTC_BILL_TYPE_DESCRIPTION char(20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
BTC_EXPIRY_DATE datetime NULL,
[key] int NOT NULL,
CONSTRAINT PK_D_BillType
PRIMARY KEY NONCLUSTERED ([key])
WITH FILLFACTOR=90 ON IndexFileGroup
)
ON IndexFileGroup
go
IF OBJECT_ID(N'dbo.D_BillType') IS NOT NULL
PRINT N'<<< CREATED TABLE dbo.D_BillType >>>'
ELSE
PRINT N'<<< FAILED CREATING TABLE dbo.D_BillType >>>'
go


.fmt definition
8.0
4
1 SQLCHAR 0 3 "~" 1 BTC_BILL_TYPE_CODE SQL_Latin1_General_CP1_CI_AS
2 SQLCHAR 0 20 "~" 2 BTC_BILL_TYPE_DESCRIPTION SQL_Latin1_General_CP1_CI_AS
3 SQLCHAR 0 26 "~" 3 BTC_EXPIRY_DATE ""
4 SQLINT 0 4 "\r" 4 key ""

cheers
john
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search