Saturday, September 28, 2013

Save images to database using SQL

Most of the time we want to save store/save images to database. In order to store image on sql server we need to store that in binary format. the most easiest way to do so in execute the SQL OPENROWSET command with SINGLE BLOB & BULK options.

Let's create one sample table and insert the sample result in it.

create table imageSave
   [img_name] varchar(250),
   [Img_binary] varbinary(max)

will insert some sample result into the imageSave table.

Insert into imageSave


FROM OPENROWSET(BULK N'F:\Images\sample-test.jpg', SINGLE_BLOB) image;

Admin(sa) & developer has rights to work with OPENROWSET command.

No comments:

Post a Comment