Commands creating format files to import txt file into sql server I'm trying to create a format file using bcp utility following the instructions on this page:

Using a format file to bulk import data

https://technet.microsoft.com/en-us/library/ms178129(v=sql.105).aspx

However, this page only discusses how to create format files for tables in the databases. My target is creating a format file for a txt file on my disk and then using the format file to import the raw data in the text file to the database. I tried the following command:

bcp C:\data.txt format nul -c -f txt1.fmt -T 

and get the following error:

A valid table name is required for in, out, or format options.

I'm using sql server 2016 and my system is windows 10 64 bit.

Can anyone help me with this, thanks in advance for your help!

Jason
You need to put in the full path for your format file.  Use the table of the database where you will be importing the data to create your format file:

bcp Database.dbo.table format nul -f c:\txt1.fmt -c -T 

Once the format file is created, then you can import the data from the txt file into your database using the format file:

bcp Database.dbo.table in c:\data.txt -f c:\txt1.fmt -T 

https://msdn.microsoft.com/en-us/library/ms162802.aspx