Search code examples
sql-serversqlcmd

"Incorret syntax near..." error when running SQL file using SQLCMD


I have this command that found on the MSDN. but it throws syntax error. Is there any keywords that i missed? I have read many forums but couldn't find the solution. I also visit guide on MSDN. but nothings happen.

 sqlcmd -S SERVER\SQL2008R2 -i sqlfile.sql

Screenshot of SQLCMD error


Solution

  • You need to run this on Command Prompt and not inside sqlcmd:

    sqlcmd -S SERVER\SQL2008R2 -U UserName -P Password -i sqlfile.sql

    i.e. C:\>sqlcmd -S SERVER\SQL2008R2 -U UserName -P Password -i sqlfile.sql