xp_cmdshell


xp_cmdshellを使用するとSQL Server から外部プログラムを呼び出すことができる


使用例は以下の通り

DECLARE @Rtn int

 EXEC @Rtn = master.dbo.xp_cmdshell 'dir c:\'

 SELECT @Rtn AS [結果]


なお、xp_cmdshellはデフォルトでは無効になっている


xp_cmdshellを有効にするSQLは以下の通り

EXEC sp_configure 'show advanced options', 1
GO

RECONFIGURE
GO

EXEC sp_configure 'xp_cmdshell', 1
GO

RECONFIGURE
GO


動作確認環境:SQL Server 2008 Express