1.

How to use xp_cmdshell in SQL?

Answer»

How to USE xp_cmdshell in SQL?
We use xp_cmdshell in SQL to run DOS command. But before use of this we need to enable xp_cmdshell by below commands. And to unable this we use below command to check it is enable or not.

use master
GO
Exec sp_configure 'show ADVANCED option'


By just using above command we get output like below.


xp cmdshell
No we need to enable this config_value to 1 and to do that we use below command

USE master;
GO
EXEC sp_configure 'show advanced option', '1';
RECONFIGURE WITH OVERRIDE;


Once above command will run we need to enable xp_cmdshell command too by below syntax


EXEC sp_configure 'xp_cmdshell', 1;
GO
RECONFIGURE;



Now we are able to run xp_cmdshell command below is ONE of the example of of one xp_cmdshell command.

xp_cmdshell 'copy c: backup c: otherfoldername;



Discussion

No Comment Found