Automated SQL script install using SQLCMD

  • Hello, I would have an application database in which I have DDL and DML scripts to install it. In Oracle I use prompts to prompt the installed for variables used in the install. Is there a way to do this in T-SQL? Also, in SQLCMD there is the -v parameter for passing in a variable. Is there a way to pass in multiple variables?

    Best Regards,

    ~David

  • I have typically handled this by using batch script (.bat) files. Assuming you are using a Windows platform, the command shell is plenty flexible enough for you to prompt for input at run time so you can set any number of variables then use the variables as parameters within the script as SQLCMD parameters or anything else.

    if you are using a unix/linux platofrm even better, I think the scripting capabilities of the shell are even easier and more powerful and will allow you to produce the same result.

    The probability of survival is inversely proportional to the angle of arrival.

  • Okay, that sounds like a good option. would you have any .cmd/SQL script examples that would demonstrate how this could be accomplished. Thank you.

    Best Regards,

    ~David

  • here is a short example of a batch file variable being set via user input (from a prompt at run time) then the variable being used in subsequent commands:

    rem prompt for server to run query on

    :getSVR

    set /p VMSVR=WhichServer?

    if "%VMSVR%" == "" goto getSVR

    sqlcmd -E -S %VMSVR% -Q "select * from master.sys.objects"

    The probability of survival is inversely proportional to the angle of arrival.

  • This is helpful. Thank you for the input.

    🙂

    Best Regards,

    ~David

  • Glad to be of assistance. good luck

    The probability of survival is inversely proportional to the angle of arrival.

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply