Thursday, November 17, 2011

[MSSQL] Copy & Delete File on Server Side

sp_configure 'xp_cmdshell', '1'
go
reconfigure

exec master.dbo.xp_cmdshell 'copy drive:\folder\filename.ext drive:\folder\filename.ext'

exec master.dbo.xp_cmdshell 'del drive:\folder\fiilename.ext'

Tested on MSSQL 2005

Reference:
http://www.sqlmonster.com/Uwe/Forum.aspx/sql-server-tools/4237/Script-to-delete-backup-files-which-are-7-days-old
http://www.mssqltips.com/sqlservertip/1020/enabling-xpcmdshell-in-sql-server-2005/

No comments:

Post a Comment