0

I want to run the following but I get an error at the '-' in front of 'U'

sqlcmd -U foo -P Bar -S server -D db -Q "use db truncate table Table1"

Thanks for the help

EDIT:

TRUNCATE TABLE table1

Does not work as it says I do not have permission.

weewa
  • 125
  • 3
  • 4
  • 14

3 Answers3

0

Specified the location of my table with

TRUNCATE TABLE server.db.table1

weewa
  • 125
  • 3
  • 4
  • 14
  • If someone else has a way to fix my original statement I will accept that in the event it works for me. Thank you! – weewa Oct 08 '12 at 16:28
0

Your syntax is correct - except that -D should be -d - but you didn't post the exact error so it isn't entirely clear what's wrong. However, I think you might be executing your sqlcmd command in Management Studio; doing that gives me this error:

Msg 102, Level 15, State 1, Line 1 Incorrect syntax near 'U'.

But sqlcmd.exe is a command-line tool, so you should execute it from a command prompt, not from SSMS (please note that SQLCMD mode in SSMS is not the same thing as running sqlcmd.exe from the command line).

Pondlife
  • 15,992
  • 6
  • 37
  • 51
0

sqlcmd -U foo -P Bar

Should be sqlcmd -Ufoo -PBar no space.