31

Is there a way to insert binary data into sql server directly from SQL Server management studio?

3 Answers 3

31

Found the answer:

SQL Server has an "OPENROWSET" command that accepts a filepath.

eg

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

Source: http://shortfastcode.blogspot.com/2009/12/insert-binary-data-like-images-into-sql.html

Sign up to request clarification or add additional context in comments.

1 Comment

This requires that OPENROWSET is enabled on the server - it is disabled by default.
28

Try this:

INSERT INTO Table (field1) VALUES (0xABCDEF)

Where 0xABCDEF is your binary data represented as an hexadecimal sequence.

Comments

1

I found no way to upload/download binary file from SSMS GUI without script.

So I switch to MySQL with Workbench. From their table editor, for a BLOB column, in the context menu, there are Load Value From File... and Save Value To File... options.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.