Loading images and any binary files (like Adobe PDF documents) to a database is not always the best option but sometimes needed. In SQL Server 2005 this process is simplified a lot with the BULK option of OPENROWSET. Here is an example of inserting image data into a VARBINARY(MAX) column (the same applies to loading an Adobe PDF file or any other binary file):
CREATE TABLE Foobar (
image_data VARBINARY(MAX));
INSERT INTO Foobar (image_data)
SELECT image_data
FROM OPENROWSET(
BULK N'C:\image.jpg',
SINGLE_BLOB) AS ImageSource(image_data);
Note the use of the SINGLE_BLOB option.
as I do to get the images of the image field and save to your hard disk
ReplyDeleteFernando,
ReplyDeleteThere is no direct SQL statement to retrieve and store an image to the file system. Here are a few links with articles that describe different methods:
http://www.dbazine.com/sql/sql-articles/larsen13
http://www.databasejournal.com/features/mssql/article.php/1443521/Copy-Text-or-Image-into-or-out-of-SQL-Server.htm
http://www.sommarskog.se/blobload.txt
greetings Plamen, I'm testing now with bcp and
ReplyDeleteEXEC master..xp_cmdshell
Hi ,
ReplyDeleteFor single image its working file. If i want to store multiple images at a time what i have to to. can you suggest me with code snippet.
Life is full of many challenges. Challenges that will make you or break you depending on how you handle it. Visit my site for more updates. God Bless to your site.
ReplyDeleten8fan.net
www.n8fan.net
Life is full of many challenges. Challenges that will make you or break you depending on how you handle it. Visit my site for more updates. God Bless to your site.
ReplyDeleten8fan.net
www.n8fan.net