문제

Say I have a .sql script stored in c:\scripts\some_script.sql.

What command do I use to execute this script from within another script or stored procedure.

For example

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

 -- does not work  
go

I am running the scripts in SSMS.

도움이 되었습니까?

해결책

Use xp_cmdshell to run sqlcmd utility to execute your script:

exec xp_cmdshell 'SQLCMD -S <Server> -E -i "C:\path\script.sql" 
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top