Sunday 7 August 2011

Running Command line commands from T-SQL

xp_cmdshell can be used to execute command line commands from T-SQL / SQL procedures.
This command can be used if you would like to use "bcp" utility from T-SQL or procedures and if you would like to do any mx record validation, etc...
eg:
xp_cmdshell "dir"

By default "xp_cmdshell" will be disabled.

How to enable
---------------
EXEC sp_configure 'show advanced options', 1
GO

RECONFIGURE
GO

-- To enable the feature.
EXEC sp_configure 'xp_cmdshell', 1
GO

-- To update the currently configured value for this feature.
RECONFIGURE
GO

For more details on how to enable, refer to the below page.
http://msdn.microsoft.com/en-us/library/ms175046.aspx

No comments:

Post a Comment