Results 1 to 7 of 7

Thread: How to Run sql script file (External) file

  1. #1
    Join Date
    Jan 2009
    Posts
    2

    How to Run sql script file (External) file

    hi to all,

    I want to run external script file (c:\test.sql) from the MSSQL command window. Is it possible in MSSQL 2005 ?.

    Thanks in advance.

  2. #2
    Join Date
    Sep 2002
    Posts
    5,938
    You can double click the file, that loads the file to ssms query windows, then execute it. Or just copy contents in the file and paste them in ssms query windows then execute.

  3. #3
    Join Date
    Jan 2009
    Posts
    2
    Thanks for reply.
    I already wrote some script lines in ssms. In between that script i want to execute the external file any command is there for invoking the external script file.

    Thanks in advance guy.

  4. #4
    Join Date
    Sep 2002
    Posts
    5,938
    then call it with sqlcmd in xp_cmdshell like:

    master..xp_cmdshell 'sqlcmd ...'

    Check syntax in books online.

  5. #5
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    If you want to run it outside of SSMS, you can use sqlcmd.exe or osql.exe

  6. #6
    Join Date
    Oct 2005
    Location
    Ireland
    Posts
    92
    Remember to enable xp_cmdshell using the surface area configuration tool if you're planning on using it.

  7. #7
    Join Date
    Sep 2002
    Posts
    5,938
    You can enable it with sp_configure.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •