goofyui
goofyui

Reputation: 3492

How to execute the SQL Script through Batch Script Command from SQL?

I am trying to execute the .sql file from batch script, but not able to execute. Script has multiple scripts such as Create Table , Stored Procedure separated by GO statement.

I tried with the below script, however script was not executed.

DB Servername : localhost\SQL2017
Authentication : Windows

sqlcmd -E -S localhost\SQL2017\MyDatabase -i C:\SQLScripts\TestScript.sql

Upvotes: 0

Views: 113

Answers (1)

Razvan Socol
Razvan Socol

Reputation: 5684

Try this instead:

sqlcmd -E -S localhost\SQL2017 -d MyDatabase -i C:\SQLScripts\TestScript.sql

You need to use the -d parameter to specify the database name. The -S parameter should contain only the server name and the instance.

Upvotes: 1

Related Questions