Inserting Files as Binary Data in MS SQL 2005
Posted on 2009-04-08 (Updated on 2019-01-24)
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:
- Open the file in your hex editor
- Select all the hex, and copy it
- Open up the query editor
- Type up your insert statement:
INSERT INTO table (binary\_field) VALUES (0x!!!)
- 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