Steps to Save/Store file into Database


You can use the below scripts to store/save the file into SQL Server database table. Please note it is not recommended to store file into database. You can store the file on file system and path in the database.

use sqlDBPool
--documents table will store files into varbinary field
--drop table documents
create table documents
(
	documentID int identity(1,1),
	doctype char(5),
	document varbinary(max)
)


--script to store/save document into table
insert into documents 
 Select 'xls', (SELECT * FROM OPENROWSET(BULK N'C:\JSpace\book1.xls', SINGLE_BLOB) AS document) document
go

select * from documents

1 thought on “Steps to Save/Store file into Database

  1. Pingback: Link Resource # 42 : Feb 01 – Feb 24 « Dactylonomy of Web Resource

Thanks for the comment, will get back to you soon... Jugal Shah