I would like to write a \'generic\' script to operate on a number of databases. The \'use databasename\' commands will be distributed in the body of the script. I would rath
Check out Scripting Variables in SQLCMD.
This enables you to put variables into your scripts in the form:
USE $(db1_name)
...some code...
USE $(db2_name)
...some code...
And have the variable values interpolated from environment variables, parameters provided at runtime, or hard coded value assignments.