Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upload a file to a varbinary with SQL Management Studio

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

like image 1000
Patrice Pezillier Avatar asked Jun 16 '10 13:06

Patrice Pezillier


People also ask

How do I upload a file to SQL Server?

In Object Explorer, connect to an instance of the SQL Server Database Engine and then expand that instance. Expand Databases, right-click the database from which to add the files, and then click Properties. In the Database Properties dialog box, select the Files page. To add a data or transaction log file, click Add.

What is Varbinary in SQL?

varbinary [ ( n | max ) ] max indicates that the maximum storage size is 2^31-1 bytes. The storage size is the actual length of the data entered + 2 bytes. The data that is entered can be 0 bytes in length. The ANSI SQL synonym for varbinary is binary varying.

How can I see Varbinary data in SQL Server?

INSERT INTO #TempTable(PK, VarBinaryColumn) SELECT PK, VarBinaryColumn FROM dbo. YourPermanentTable; If you need to convert the varbinary data back to the original file text format in T-SQL, you can use CAST or CONVERT to convert to varchar or nvarchar as long as the data was originally ASCII or Unicode.


2 Answers

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
like image 59
SQLMenace Avatar answered Nov 15 '22 21:11

SQLMenace


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.

like image 38
John Sansom Avatar answered Nov 15 '22 21:11

John Sansom