Is it possible to execute a text file from SQL query?

后端 未结 9 940
星月不相逢
星月不相逢 2020-12-04 21:35

I have a number of generated .sql files that I want to run in succession. I\'d like to run them from a SQL statement in a query (i.e. Query Analyzer/Server Management Studi

9条回答
  •  暖寄归人
    2020-12-04 22:03

    For Windows Authentication, if you are running as another user: Open Command Prompt as your Windows user (Right click on it, Open File Location, Shift + Right Click, Run as a different user)

     sqlcmd -S localhost\SQLEXPRESS -d DatabaseName-i "c:\temp\script.sql"
    

    Or if you are using Sql Server user:

    sqlcmd -S localhost\SQLEXPRESS -d DatabaseName-i "c:\temp\script.sql" -U UserName -P Password
    

    Replace localhost\SQLEXPRESS with you server name if not local server.

提交回复
热议问题