Friday, February 26, 2016

Add/upload documents in image or varbinary datatype

This post related to SQL Server, question arise in my mind where all the documents goes in database, if we can save all documents images, videos  in database, answer is yes, we can do. I have started looking into this, how we can do this. So my knowledge which contains couple of hour and success is below. You try in SQLServer and create new table, then place any document at right place and change the path and execute the below query.

create table documents(id int not null, doctype varchar(4), content varbinary(max));

INSERT INTO documents(id, doctype, content)
    2 as id,
    '.pdf' AS doctype,
    * FROM OPENROWSET(BULK N'D:\common\ebooks2\India-Year-Book-2009.pdf', SINGLE_BLOB) AS Document;

select * from documents;

Add comments if you like the post.

No comments:

Post a Comment

web stats