开发者

SQL Server import of file created through bcp

I'm currently reviewing how to import a file created from bcp in SQL Server on one computer into my local SQL Server. This is a datafile I received from a 3rd party so I ha开发者_JS百科ve no idea of the data structure etc. of the information. My SQL Server skills are quite new so please bear with me :) I've reviewd the bcp documents and attempted the following:

bcp TestDatabase in File.bcp -T
Results: Invalid Object name 'TestDatabase'

I created the test database TestDatabase and tried the query again but with the same response. I then added -Slocal and got a login timeout, seems like progress!

I removed the -T flag and tried varying combinations of usernames and passwords without any luck.

So I guess to start, is there an underlying issue I'm missing, syntax I'm not following etc. or should I just play around with the creds for my local SQL Server?


You need to specify the server, username, and table. Try this:

bcp TestDatabase..SomeTableName in File.bcp -S Server -U Username -P Password


If you look at the bcp Utility docs

-T means to use Integrated Security (your logged in account)

-Sis the server name parameter.

These two parameters are not interchangeable.

You can only use the -U and -P in place of -T if you have SQL Authentication turned on (and you shouldn't if you can avoid it)

Finally Chris Shain is correct. You need to specify Schema and table or ViewName, not just a DB Name, as well as the Server (-S)

Also from the documentation (and the point E.J. Brennan was making)

To import data into a table, you must either use a format file created for that table or understand the structure of the table and the types of data that are valid for its columns.

So you can't expect to just take a file and have bcp magically make a table for you. You need to use SSIS to help you or some other tool to do that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜