SQL中用系统存储过程xp_fileexist来判断文件是否存在
一、xp_fileexist调用说明
1、
xp_fileexist "c:\autoexec.bat"
File Exists File is a Directory Parent Directory Exists
----------- ------------------- -----------------------
1 0 1
--1表存在,0表不存在
(1 row(s) affected)
------------------------------------------
2、
declare @result int
exec xp_fileexist 'c:\autoexec.bat', @result output
@result=1表文件存在
@result=0表文件不存
二、测试
if exists (select *
from sysobjects
where type='u'
and
name = 'temp_xp_fileexist')
begin
drop table temp_xp_fileexist
end
create table temp_xp_fileexist(a bit,b bit,c bit)
--declare @sql nvarchar(1000)
--set @sql=@path+@fname
Declare @result int
--文件夹存在 011 0
--insert into temp_xp_fileexist
--exec xp_fileexist 'C:\test'
--insert into temp_xp_fileexist
--exec xp_fileexist 'C:\test',@result output
--文件夹不存在 001 0
--insert into temp_xp_fileexist
--exec xp_fileexist 'C:\testss'
--insert into temp_xp_fileexist
--exec xp_fileexist 'C:\testss',@result output
--文件夹存在、文件存在 101 1
--insert into temp_xp_fileexist
--exec xp_fileexist 'C:\test\test.txt'
--exec xp_fileexist 'C:\test\test.txt',@result output
--文件夹存在、文件存在 000 0
insert into temp_xp_fileexist
exec master.dbo.xp_fileexist 'C:\testsdf\test.txt'
exec xp_fileexist 'C:\testsdf\test.txt',@result output
--文件夹存在、文件不存在 001 0
--insert into temp_xp_fileexist
--exec xp_fileexist 'C:\test\testsdfs.txt'
--exec xp_fileexist 'C:\test\testsdfs.txt',@result output
select * from temp_xp_fileexist
select @result
drop table temp_xp_fileexist
三、定义成文件判断函数
create function dbo.FileExist(
@filePath nvarchar(600),
@fileName nvarchar(400)
) returns int
as
begin
declare @result int
declare @sql nvarchar(1000)
set @sql=@filePath+@fileName
exec master.dbo.xp_fileexist @sql,@result output
return @result
end
分享到:
相关推荐
在SQL Server中可以使用系统内部存储过程xp_fileexist判断文件是否存在,如果存在再使用xp_cmdshell删除文件。xp_fileexist除了可以判断文件是否存在外,还可以判断文件夹是否存在,下面是下使用这两个的示例。 删除...
SQL Server阻止了对组件xp_cmdshell过程的解决方案。 错误描述:SQL Server阻止了对组件‘xp_cmdshell’的过程‘sys.xp_cmdshell’的访问。因为此组件已作为此服务嚣安全配置的一部分而被关闭。系统管理员可以通过...
XP_CMDSHELL存储过程是执行本机的CMD命令,要求系统登陆有SA权限,也就是说如果获得SQLSERVER的SA命令,那就可以在目标机为所欲为了,知名软件“流光”使用的应该也是这个存储过程来实现在目标机上的操作。
SQL Server如何启用xp_cmdshell组件【错误描述】: SQL Server阻止了对组件‘xp_cmdshell’的过程‘sys.xp_cmds
SQL_Server_存储过程_-_hoojo_-_博客园
存储过程sys.xp_fileexist 用于判断文件是否存在,参数是文件(file)的路径或目录的路径: exec master.sys.xp_fileexist 'D:test.txt' 该存储过程返回的结果集有一行数据,三个字段,如下图: 二,创建子目录 ...
开启SQL 的xp_cmdshell脚本
sqlserver数据库加密工具,可以加密表,视图,存储过程,整个数据库等。是开发人员的必备工具!
sql server系统存储过程,sql server系统存储过程
SQLServer阻止了对组件'xp_cmdshell'的过程'sys.xp_cmdshell'的访问,因为此组件已作为此服务器安全配置的一部分而被关闭。系统管理员可以通过使用sp_configure启用'xp_cmdshell'。有关启用'xp_cmdshell'的详细...
C# SQL 存储过程 添加 修改 删除 查询数据
Microsoft SQL Server 恢复 XP_CMDSHLL 功能的命令行
资源名称:SQL_Server存储过程调试指南内容简介: 存储过程( Stored Procedure)是一组为了完成特定功能的 SQL 语句集,经编译后存储在数据库中。用户通过指定存储过程的名字并给出参数(如果该存储过程带有参数)来...
SqlServer2012安装包 cn_sql_server_2012_enterprise_edition_with_sp1_x64_dvd_1234495.iso
存储过程SQL存储过程SQL存储过程SQL存储过程SQL存储过程SQL存储过程SQL存储过程SQL存储过程SQL存储过程SQL存储过程SQL存储过程SQL存储过程SQL存储过程SQL存储过程
Sql_Server中如何判断表中某列是否存在
SQL SERVER2000数据库备份和恢复存储过程
MS SQL入侵(小心 xp_cmdshell)
SQL Server沒有辦法加密欄位裡的資料, 換言之, 只要有人取得存取資料庫或其檔案的權限, 就能夠很容易地檢視、複製、甚至修改您存在資料庫裡的機密資料, 例如信用卡資料、薪水獎金的資料。許多資訊安全規範, 例如CISP...