• Sqlfrenzy (7/30/2009)


    SanjayAttray (7/30/2009)


    Sqlfrenzy (7/30/2009)


    An easy way of executing scripts.....

    Create a batch file and place it in the folder containing the scripts...

    @for /r %%s in (.) do (echo ..............%%s /b >> "C:\Build Deployment\output\Log.txt"

    sqlcmd -d Dbname -Usa -Psql2005 -i "%%s" >> "C:\Build Deployment\output\Log.txt")

    Problem with this is that you have to give either SA or Login ( mostly administrator) password in P parameter and that could be read by other people working on project.

    It would be OK to run/call commands in batch when you are doing it on fly.

    well.... u need a login to connect to sql server any how......and the person implementing the changes on production server are mostly administrators....

    You can use the -E option for sqlcmd instead of having user and pass in there.

    From BOL:

    -E

    Uses a trusted connection instead of using a user name and password to log in to SQL Server. sqlcmd uses the trusted connection option by default.

    The -E option ignores possible user name and password environment variable settings such as SQLCMDPASSWORD. If the -E option is used together with the -U option or the -P option, an error message is generated.