12

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

Dylan Corriveau
  • 2,561
  • 4
  • 29
  • 36
Patrice Pezillier
  • 4,476
  • 9
  • 40
  • 50

2 Answers2

16

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
SQLMenace
  • 132,095
  • 25
  • 206
  • 225
  • 1
    OK but is there a way without SQL query ? With the GUI ? – Patrice Pezillier Jun 16 '10 at 13:57
  • caveat from [MS docs](https://learn.microsoft.com/en-us/sql/t-sql/functions/openrowset-transact-sql) this example was stolen from: requires the `ADMINISTER BULK OPERATIONS` permission – NH. Nov 29 '17 at 23:35
7

In short, using SQL Server Management Studio (SSMS), no.

The options are to either complete your task via T-SQL or to roll your own solution/application.

A solution devised using SQL Server Integration Services (SSIS) may also be possible.

John Sansom
  • 41,005
  • 9
  • 72
  • 84