Search notes:

SQL Server: Format files

Format files are required for the T-SQL command openrowset(bulk …) statement and can optionally be used with bcp.
There are XML and non-XML format files.

Structure of non-XML format files

The first line specifies the version number.
The second line specifies how many columns are described in the format file.
Each of the following lines corresponds to a column.
A column specification consists of eight parts:
Host file field order
Host file data type See column Host file data type.
Prefix length Valid values are 0, 1, 2, 4 and 8. 0 can be used to avoid specifying the length prefix, but a value must be supplied if the field contains null values.
Host file data length Maximum length (bytes) of data in respective column
Terminator Delimiter with which field are separated from one another.
Server column order Set to 0 in order to not fill values in respective column.
Server column name The name seems to have no influence, but must not be null.
Collation of the column
14.0
4
1     SQLCHAR    0  10  "\t"     1    colName_one  *
2     SQLCHAR    0  20  "\t"     2    colName_two  *
3     SQLCHAR    0  42  "\t"     3    colName_three  *
4     SQLCHAR    0   3  "\r\n"   4    colName_four  *

Creating a format file

bcp allows to quickly create a format file (whose name is specified with the -f option) that matches the characteristics of an existing table with format nul:
bcp tq84_tab format nul -f transfer.fmt  -T -d tq84_db -c

See also

SQL Server: Import / export

Index