Inserting an image into Image column

Last month I was trying to insert an image(file) directly via sql query into my MS SQL Server database table.

I used the following;

DECLARE @myImage binary
SET @myImage = (SELECT * FROM OPENROWSET(BULK N'F:\porsche.jpg', SINGLE_BLOB) AS i)

In this query we can declare a binary variable and set its content to the "porsche.jpg". After this, it will be easy to insert the data via insert query.

INSERT INTO [USER]
([UserKey]
,[Icon]
VALUES
(2, @myImage)

Comments

Popular posts from this blog

Space Character Problem on IE 6, 7, and 8

Does Netflix work on iOS 5 Beta 4?

AWS encryption chart (SSE-S3 vs SSE-KMS vs SSE-C)