SQL scripts to insert File to BLOB field and export BLOB to File
- Using SQL server 2008, you can saved images / files to BLOB binaries and retrieve back them to file system.
- Import
Test table structure:
CREATE TABLE [dbo].[TestBlob](
[tbId] [int] IDENTITY(1,1) NOT NULL,
[tbName] [varchar](50) NULL,
[tbDesc] [varchar](100) NULL,
[tbBin] [varbinary](max) NULL
) ON [PRIMARY] - Insert file to BLOB test table is fairly easy. Open Microsoft SQL server management studio, run the below script, script is inserting one pdf, doc, image and exe fil.
Insert TestBlob(tbName, tbDesc, tbBin) Select '81.pdf','PDF file', BulkColumn from Openrowset( Bulk 'C:\blob\udoc\81.pdf', Single_Blob) as tb
Insert TestBlob(tbName, tbDesc, tbBin) Select 'mountain.jpg','Image jpeg', BulkColumn from Openrowset( Bulk 'C:\blob\udoc\mountain.jpg', Single_Blob) as tb
Insert TestBlob(tbName, tbDesc, tbBin) Select 'Questionnaire.docx','Doc Question', BulkColumn from Openrowset( Bulk 'C:\blob\udoc\Questionnaire.docx', Single_Blob) as tb
Insert TestBlob(tbName, tbDesc, tbBin) Select 'txpeng542.exe','Texpad Exe', BulkColumn from Openrowset( Bulk 'C:\blob\udoc\txpeng542.exe', Single_Blob) as tb