I did this on SQL 2019:
CREATE TABLE bcptest (col1 nchar(20) NULL,
col2 nchar(20) NULL,
col3 nchar(20) NULL,
col4 nchar(20) NULL)
INSERT bcptest(col1, col2, col3, col4)
VALUES('Stravinsky', 'Chaikovsky', 'Rimsy-Korsakov', 'Prokofieff'),
('Debussy', 'Ravel', 'Saint-Saëns', 'Chopin')
Then I ran in a command-line window:
bcp tempdb.dbo.bcptest format nul -x -f slask.fmt -n -S .\DIXNEUF -T
bcp tempdb.dbo.bcptest format out -f slask.fmt -S .\DIXNEUF -T
This completed normally. Then I ran in SQL:
TRUNCATE TABLE bcptest
And back in the command-line window I ran:
bcp tempdb.dbo.bcptest in slask.bcp -f slask.fmt -S .\DIXNEUF -T
This completed successfully.
Now there are some details missing from your post:
- The actual CREATE TABLE statement.
- Which version of bcp you are using. (
bcp -v
will tell you.) - The actual format file generated.
There is also one thing that strikes me as funny. The file has a suffix of .csv, but you use the option -n
for native format. CSV is text format, but native format is binary. In a native file there are no delimiters. Integer values are always four bytes. And nchar(20) values are prefixed by two bytes giving the length of the values.
Also, you would use the option to generate a format file, if you are exporting a table to import it elsewhere. If you have a file you want to import, you will have to craft the format file by hand (if format cannot be expressed with help of the -t
and -r
options.)
Of the two formats for the format file, I much prefer the old one. The XML format does not give any extra powers, but is only bulky.