Insert binary data like images into SQL Server

A fairly common problem is inserting data directly into binary data columns in SQL Server without a front-end application. The example below is the simplest solution I've seen and can be run straight from SQL Server Management Studio (SSMS).

In the below example I'm updating the an image column 'Icon' with an image file saved on the hard drive.

Update myTable
set Image = (
SELECT *
FROM OPENROWSET(BULK N'C:\image.png', SINGLE_BLOB) test)
where ImageID = 1

1 comment:

  1. its seems easy, but before i'm going to try it ,is there another way to insert this kind of data without using the insert method??
    becaues I have a huge data to be inserted & if i'm going to use this way it will take for ever to do it :S
    pls help me as soon as possible :(

    ReplyDelete