在SQL中如何将硬盘上的文件删除?

 所属目录:Java   |   类型:技术问答   |   时间:2007-05-21
 问题:

在删除记录时,同时要将硬盘上的文件删除,已知文件的路径在对应的字段中,如何做?  
  最好是在触发器中处理。

· 网友精彩回答:

发表者:libin_ftsafe

exec   master..xp_cmdshell   del   c:\1.txt  
  go  
 

发表者:yisa

測試數据:  
  表test中有id,   path字段.  
  id       path  
  1         c:\gg.txt  
  2         c:\book\sql.doc  
  3         d:\hh.txt  
  4         d:\a.xls  
   
  create     proc       testp     @id   int  
  as  
  set     nocount     on  
  declare     @temp     varchar(100)  
  select     @temp=path     from     test     where     id=@id  
  set     @temp=del     +@temp               --或set   @temp=rd         /s/q       \         +@temp  
  exec         master..xp_cmdshell       @temp  
  go  
   
  exec     testp     3  
  go  
   
  注意:(1)set     @temp=del     +@temp   中del     是刪除指定的文件名.  
  (2)set   @temp=rd         /s/q       \         +@temp   中的rd     /s/q     \     是刪除指定文件夾下的所有文件名.  
             
 

.
处理 SSI 文件时出错
© 2006-2008 All Rights Reserved