how to create a batch file to execute files in production servier.

  • hi to all,

    how can i create a batch file to execute bunch of scripts in production server. i.e., we have to give the production servername,databasename as input to that batch file.

    thanks

    🙂

  • Hi,

    Good question but I hope you understand that Programming cannot be taught. You can try downloading scripts from SQL Server Central and accordingly write your own. Below is a good link which will tell more on this side.

    http://www.microsoft.com/technet/scriptcenter/scripts/sql/default.mspx?mfr=true

    Regards

    GURSETHI

  • You can use sqlcmd in the batch

    example script:

    SET usernamevar=sa

    SET pwdvar=DATABASEPASSWORD

    SET sernamevar=DATABASESERVER

    SET dbnamevar=DATABASENAME

    sqlcmd -U %usernamevar% -P %pwdvar% -S %sernamevar%-d %dbnamevar% -i DATABASESCRIPT.sql -o DATABASESCRIPTREPORT.txt

  • Hi,

    thanks for your great response. it was very useful to me.

    Thank you,

    🙂

  • hi,

    i have tried with this :

    SET usernamevar=

    SET /P usernamevar=Enter Username:

    SET pwdvar=

    SET /P pwdvar=enter password:

    SET sernamevar=

    SET /P sernamevar=Enter servername:

    SET dbnamevar

    SET /P dbnamevar=Enter databasename:

    sqlcmd -U %usernamevar% -P %pwdvar% -S %sernamevar% -d %dbnamevar% -i DATABASESCRIPT.sql -o DATABASESCRIPTREPORT.txt

    🙂

  • There is also the OSQL command that you could call from a BATCH file. Here's an example below:

    osql -E -n-1 -q "Select * From SERVER.DB.DBO.Table"

    Google / Knowledge base search for more details on the command.

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

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