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

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

Is Wharton Business Foundations Specialization Good?

Sending Large Data with JSON