首页 > 解决方案 > 可以从 SQL Server 数据库中的存储过程运行 Linux 脚本吗?

问题描述

我想从存储过程运行 shell 脚本作为一种解决方法,以实现工具默认不提供的功能。

可能吗?数据库是 SQL Server,bash shell

标签: sql-serverdatabasebashshell

解决方案


是的。查看https://docs.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/xp-cmdshell-transact-sql?view=sql-server-ver15。要使用 xp_cmdshell 您必须激活它,这是通过以下命令完成的:

-- this turns on advanced options and is needed to configure xp_cmdshell
sp_configure 'show advanced options', '1'
RECONFIGURE
-- this enables xp_cmdshell
sp_configure 'xp_cmdshell', '1' 
RECONFIGURE

推荐阅读