我的目录中有一个文件 \\myServer\Admin\temp\testtemp.txt
我需要编写一个 TSQL
- 搜索
testtemp.txt
文件。 - 如果存在,请创建其副本并将其重命名为
Copytesttemp.txt
如果上面的目录中已有
testtemp.txt
,如下所示\\abcd\Admin\temp\Copytesttemp.txt
然后将其删除并重新创建
Copytesttemp.txt
我该如何实现它?谢谢。
最佳答案
您可以使用 xp_cmdshell 运行任何您喜欢的 DOS 命令,例如
declare @cmdstring varchar(1000)
set @cmdstring = 'copy \\myServer\Admin\temp\testtemp.txt \\myServer\Admin\temp\Copytesttemp.txt'
exec master..xp_cmdshell @cmdstring
只需确保您的安装中启用了 xp_cmdshell。
关于sql-server - SQL服务器2008 : Copy a file and rename it,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10501274/