Skip to content
Fragmented Development

Inserting Files as Binary Data in MS SQL 2005

I recently came upon an extremely quick, simple, and brutal to insert a file into a MS SQL database using only the query editor and a hex editor:

  1. Open the file in your hex editor
  2. Select all the hex, and copy it
  3. Open up the query editor
  4. Type up your insert statement: INSERT INTO table (binary\_field) VALUES (0x!!!)
  5. Replace the three exclamation points (!!!) by pasting the data you copied from your hex editor

Now, this is far from recommended practice. In fact, this is a damn ugly way to do things. However, I didn't want to muck around in a scripting language, and the other SQL methods I found had too much SQL to them. SQL is not my strong suit, so voila – there you have it.

Tags: sql


Add Your Comment