Is it possible to insert a file in a varbinary(max) column in Transact-SQL? If yes, I would be very please to have a code snippet to at least give me an idea how to do that.
Thanks
varbinary [ ( n | max ) ] n can be a value from 1 through 8,000. max indicates that the maximum storage size is 2^31-1 bytes.
The FileTable feature enables enterprise customers to store unstructured file data, and directory hierarchies, in a SQL Server database. The feature addresses the requirements for non-transactional access and Windows application compatibility for file-based data.
You can insert rows into a view only if the view is modifiable and contains no derived columns. The reason for the second restriction is that an inserted row must provide values for all columns, but the database server cannot tell how to distribute an inserted value through an expression.
It's so easy - once you know it! :-) Found this on Greg Duncan's blog a while ago:
INSERT INTO YourTable(YourVarbinaryColumn)
SELECT * FROM
OPENROWSET(BULK N'(name of your file to import)', SINGLE_BLOB) AS import
And here's the MSDN library documentation on it.
Marc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With