□MSSQL T-SQLでファイル出力する方法

xp_cmdshellコマンドで、'echo "hoge" > log.txt'と言った引数で実行すると
指定したファイルに出力できる。

例)
EXEC master..xp_cmdshell 'echo "hoge" > log.txt'

 但し、MS-SQLServer2005では、sysadmin権限があっても、xp_cmdshellの実行権限が
不足するため、以下を実行する必要がある。

-- To allow advanced options to be changed.
EXEC sp_configure 'show advanced options', 1
GO
-- To update the currently configured value for advanced options.
RECONFIGURE
GO
-- To enable the feature.
EXEC sp_configure 'xp_cmdshell', 1
GO
-- To update the currently configured value for this feature.
RECONFIGURE
GO
最終更新:2009年03月04日 20:06