How to read a .sql file from the local hard drive and execute the commands given on the SQL server?

  • Hi All,

    Can any of you help me in reading a text/sql file which is stored on the local hard drive and run all the commands given in the file.

    My scenario is something like this.....suppose I have modified one SP and sent it to my client. One way of updating / creating the new SP is open the text/sql file in notepad and copy the content the SQL query window and then press F5.

    But I dont want to follow this path. Is there any way that I send the text/sql file and client stores it on the local drive and execute the file on SQL server by giving the path of the file.

    Thanks in advance..!!

    Sanjeev

  • to run the scripts from the command line you can use SQLCMD.

    http://msdn.microsoft.com/en-us/library/ms170207.aspx"> http://msdn.microsoft.com/en-us/library/ms170207.aspx

    or else you can open the scripts in SSMS using File -->Open File

  • Hey

    This is the script for you.

    OSQL -E -S [SQL Instance Name] -n -i [path ..c:\] >> c:\resutls.txt

    The above script use Windows authentation and connectes to the sql server and executes sql file from the path specified and log the results to c:\results.txt..

    The above command you schedule through SQL Server Agent or Windows Scheduler...

    Rajesh Kasturi

  • Rajesh kasturi (4/24/2009)


    Hey

    This is the script for you.

    OSQL -E -S [SQL Instance Name] -n -i [path ..c:\] >> c:\resutls.txt

    The above script use Windows authentation and connectes to the sql server and executes sql file from the path specified and log the results to c:\results.txt..

    The above command you schedule through SQL Server Agent or Windows Scheduler...

    Be aware that OSQL is to be removed from future versions of SQL server, it is recommended to use the SQLCMD function instead..

Viewing 4 posts - 1 through 3 (of 3 total)

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