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

Configure hosts File in Android

Is Wharton Business Foundations Specialization Good?

iTunes cannot restore the iPhone because Find My iPhone is on and applications are gone!