当前位置: 移动技术网 > IT编程>数据库>MSSQL > 用SQL语句从电脑导入图片到数据库

用SQL语句从电脑导入图片到数据库

2019年09月02日  | 移动技术网IT编程  | 我要评论

姜芷柔,用药安全网,基督教牧师讲道集

--创建图片表
create table w_pic
(
    id int,                --编号
    wpath varchar(80),    --完整路径
    pic varchar(80),    --图片名称,不带后缀
    img image            --图片内容
)

--图片表中插入数据
insert into w_pic(id,wpath,pic)
select 1, 'c:\users\w\desktop\产品图片\2#加工图34-c专用.jpg','2#加工图34-c专用'
union all
select 2, 'c:\users\w\desktop\产品图片\129.jpg','129'

--创建游标
declare cur_pic cursor for select id,wpath,pic from w_pic;
declare @id int, @path varchar(80), @pic varchar(80), @str varchar(100);
open cur_pic;
fetch next from cur_pic into @id, @path, @pic;
while @@fetch_status=0
begin
    set @str=str(@id);    
    --插入图片数据
    execute ('update w_pic set img=(select * from openrowset(bulk n'''+@path+''', single_blob) as photo) where id='+@str);
    fetch next from cur_pic into @id, @path, @pic;
end
close cur_pic;
deallocate cur_pic;

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网