I have a large SQL script which I am trying to run using the command line.
I have found these instructions here: https://learn.microsoft.com/en-us/sql/relational-databases/scripting/sqlcmd-run-transact-sql-script-files
Which seem to say that I can use this command:
sqlcmd -S myServer\instanceName -i C:\myScript.sql
Which makes sense to me. I assume I would use the same server details as I would in a Web.Config connection string.
The issue is, this does not seem to specify the database name to run the script on.
I think this is because it is assumed that the SQL file will have the DB name, but my file is too big to open to confirm this.
Also, I would like to specify the DB name to be double safe.
Can anyone advise how to do this?
Also, if anyone can advise how I can read the first line of a file using the command line that would be great aswell..
Thanks in advance
sqlcmd -?. That tells you use can use-dto specify the database name. Thus:sqlcmd -S myServer\instanceName -i C:\myScript.sql -d MyDatabase. This command also assumes you are using integrated security.