sql-server - SQL服务器2008 : Copy a file and rename it

标签 sql-server sql-server-2008 tsql

我的目录中有一个文件 \\myServer\Admin\temp\testtemp.txt

我需要编写一个 TSQL

  1. 搜索 testtemp.txt 文件。
  2. 如果存在,请创建其副本并将其重命名为 Copytesttemp.txt
  3. 如果上面的目录中已有testtemp.txt,如下所示

    \\abcd\Admin\temp\Copytesttemp.txt
    
  4. 然后将其删除并重新创建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/

相关文章:

sql - SQL脚本中的Week()函数

Python函数缩进错误: unexpected indent

sql-server - 更改 AD 登录凭据后返回无效的 susername_sname()/SYSTEM_USER

sql - 使用过滤器更新存储过程

asp.net - Visual Studio 2012 - 数据库发布向导已停止?

sql server 将日期时间转换为另一个时区?

tsql - 嵌套的 SELECT 语句以我不理解的方式进行交互

sql-server - 如何从 SQL Server 中选择 y 行之后的数据顶部 x 数据

sql-server-2008 - 文本数据类型在 where 子句中表现不佳

SQL Server 2005 和临时表范围