7

I want to import a table while keeping the identity column.

In cmd, I enter:

bcp database.edg.Hello in C:\Users\Tech\Downloads\p.csv -c -E 
       -S 349024ijfpok.windows.net\MSSQLSERVER -T

Which returns:

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

Is this an issue with the syntax?

SteveC
  • 15,808
  • 23
  • 102
  • 173
user5112255
  • 81
  • 1
  • 3
  • `database.edg.Hello` - is that a valid database name, schema name, and table name? If you connect to your server, does `select * from database.edg.Hello` succeed? – Greg Jul 14 '15 at 17:15
  • It doesn't. edg.Hello works, but when I add my database name in front of it it just gives a syntax error There is a dash in the real database name, like da-ta-base. It says "incorrect syntax near '-'. – user5112255 Jul 14 '15 at 17:32
  • 6
    bracket it. `[database-name].[edg].[Hello]` – Greg Jul 14 '15 at 18:47

1 Answers1

5

You need brackets for database information. I usually use colon " for path as well just to be sure. Complete command:

bcp [database].[edg].[Hello] in "C:\Users\Tech\Downloads\p.csv" -c -E 
       -S 349024ijfpok.windows.net\MSSQLSERVER -T
SteveC
  • 15,808
  • 23
  • 102
  • 173
Ogglas
  • 62,132
  • 37
  • 328
  • 418
  • Is this correct? I've used database details without the square brackets, except where there were problem characters, e.g. a database named "ddb-low" caused the error when I used ddb-low.dbo.Person but it went away when I changed to [ddb-low].dbo.Person – SteveC Jun 06 '19 at 11:06
  • @SteveC Yes you need them for bcp commands, at least I got errors without them. – Ogglas Jun 06 '19 at 11:35
  • Puzzled ... I can happily do exports with name like SpikeDb.dbo.Person but I get the error if I try ddb-low.dbo.Person and the error goes away when I use [ddb-low].dbo.Person – SteveC Jun 06 '19 at 11:39