-- 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
---xp_cmdshell 'cd C:Program FilesMicrosoft SQL Server90ToolsBin'
xp_cmdshell 'dir *.exe'

SELECT NAME,NAME FROM SYS.OBJECTS
xp_cmdshell 'bcp northwind.dbo.orders out c:mytest -T -c'
declare @sql nvarchar(max)
set @sql=''
select @sql=@sql+' xp_cmdshell '+'''bcp northwind.dbo.'+quotename(name)+' out c:'+name+'.dat -T -c '+''' ' from sys.objects
where type='u';
select @sql
exec (@sql)
本文介绍如何通过 SQL Server 的 sp_configure 存储过程启用高级选项及特性,例如 xp_cmdshell,并演示了如何使用该特性执行系统命令、导出数据库表到文件等操作。
2659

被折叠的 条评论
为什么被折叠?



