How to execute a cmd file?

The following sample copy file command shell can be saved into a file called weeklybackup.cmd:

XCOPY D:\backup\inventory.bak \\ServerIP\D\$\backup\inventorydaily.bak /Q /Y

The cmd file can contain other operating system commands as well. It can be executed from xp_cmdshell or SQL Server Agent just by giving the name "weeklybackup.cmd". The file can be edited with NotePad.

Related article: