Upload a file to a varbinary with SQL Management Studio

Patrice Pezillier picture Patrice Pezillier · Jun 16, 2010 · Viewed 8.9k times · Source

Is there any way to upload a file to a varbinary with SQL Management Studio without writting a manual SQL query ?

Answer

SQLMenace picture SQLMenace · Jun 16, 2010

use OPENROWSET

example

USE AdventureWorks2008R2;
GO
CREATE TABLE myTable(FileName nvarchar(60), 
  FileType nvarchar(60), Document varbinary(max));
GO

INSERT INTO myTable(FileName, FileType, Document) 
   SELECT 'Text1.txt' AS FileName, 
      '.txt' AS FileType, 
      * FROM OPENROWSET(BULK N'C:\Text1.txt', SINGLE_BLOB) AS Document;
GO