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
-d - Specifies the database name - learn.microsoft.com/en-us/sql/tools/sqlcmd-utility – Ctznkane525
sqlcmd -S myServer\instanceName -i C:\myScript.sql -d DatabaseName
in my case I needed SQL Server Authentication
sqlcmd -d database_name -U sa -P Password -S 192.168.1.1 -i "D:\tmp\script.sql"
so I launched sqlcmd with these switches. I Hope that this can help somebody
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With