Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert a blob into a database using sql server management studio

How can I easily insert a blob into a varbinary(MAX) field?

As an example:

thing I want to insert is: c:\picture.png
the table is mytable
the column is mypictureblob
the place is recid=1

like image 592
Toad Avatar asked Oct 29 '09 13:10

Toad


People also ask

How do I insert an image into SQL Server Management Studio?

1) Bring up SQL Server Management Studio. 2) Connect, and open the database you want to add the image to. 3) Expand the tables, and either add a new table with an appropriate index field, or right click teh table and select design. 4) Add a field called "myImage", and make its datatype "image".

How do I create a BLOB column in SQL Server?

Use the following TSQL statement: USE master; GO CREATE DATABASE Test; GO USE Test; GO CREATE TABLE BLOBTest ( TestID int IDENTITY(1,1), BLOBName varChar(50), BLOBData varBinary(MAX) ); In this example, the column name is BLOBData, but the column name can be any standard SQL name.


1 Answers

You can insert into a varbinary(max) field using T-SQL within SQL Server Management Studio and in particular using the OPENROWSET commmand.

For example:

INSERT Production.ProductPhoto  (     ThumbnailPhoto,      ThumbnailPhotoFilePath,      LargePhoto,      LargePhotoFilePath ) SELECT ThumbnailPhoto.*, null, null, N'tricycle_pink.gif' FROM OPENROWSET      (BULK 'c:\images\tricycle.jpg', SINGLE_BLOB) ThumbnailPhoto 

Take a look at the following documentation for a good example/walkthrough

Working With Large Value Types

Note that the file path in this case is relative to the targeted SQL server and not your client running this command.

like image 57
John Sansom Avatar answered Sep 28 '22 01:09

John Sansom