Friday, December 22, 2017

SQL SERVER - How insert image (.png) to table

Table has column IMAGE that is varbinary type:
create table app_images
( 
  ident varchar( 25 ) not null primary key,
  [size] int check ( [size] in ( 16, 32 ) ),
  [image] varbinary( max ) 
);
For inserting (.png) image to table use this code:
insert into app_images 
( ident, [size], [image] ) 
select 'tablet_32', '32', bulkcolumn 
from openrowset( bulk 'c:\db\images\tablet_32.png', single_blob ) as test

No comments:

Post a Comment