--创建图片表
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\产品图片#加工图34-c专用.jpg','2#加工图34-c专用'
union all
select 2, 'c:\users\w\desktop\产品图片9.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;