簡體   English   中英

如何從另一個腳本執行目錄中的SQL腳本?

[英]How to execute SQL script in directory from another script?

假設我有一個存儲在c:\\scripts\\some_script.sql.的.sql腳本c:\\scripts\\some_script.sql.

我用什么命令從另一個腳本或存儲過程中執行此腳本。

例如

create procedure dbo.sp_execute_script
    @script_location varchar(100)   
as  
    execute(@script_location)

 -- does not work  
go

我在SSMS中運行腳本。

使用xp_cmdshell運行sqlcmd實用程序來執行腳本:

exec xp_cmdshell 'SQLCMD -S <Server> -E -i "C:\path\script.sql" 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM