SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Query to import multiple image file to SQL server 2008 Database


Query to import multiple image file to SQL server 2008 Database

Author
Message
assefam
assefam
SSC Rookie
SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)

Group: General Forum Members
Points: 33 Visits: 210
I have a database with different tables. one of these tables has an image column more than 50, 000 records.
I have also 40,000 image files in a separate folder C:\ImageFolder with file names the same as primary Key values of the record in the table.
Question: How can I insert these multiple image file from C:\ImageFolder to the corresponding record in the image column.
E.g. Table Name SampleTable (Col_PK, Name,Picture) with sample data (four records)
Col_PK          Name      Picture
1001 XXX NULL
1002 YYY NULL
1003 ZZZ NULL
1004 ddd NULL



C:\ImageFolder -- has the following three image files
1001.png, 1002.png , 1004.png
Remark: Size of each file is less than or equal to 50KB and will be stored in the database as binary file
How to import image file:
1001.png -> To Record with Col_pk=1001
1002.png -> To Record with Col_pk=1002
1004.png -> To Record with Col_pk=1004
bleroy
bleroy
SSC Veteran
SSC Veteran (258 reputation)SSC Veteran (258 reputation)SSC Veteran (258 reputation)SSC Veteran (258 reputation)SSC Veteran (258 reputation)SSC Veteran (258 reputation)SSC Veteran (258 reputation)SSC Veteran (258 reputation)

Group: General Forum Members
Points: 258 Visits: 739
Have a look at this:
http://www.sqlservercentral.com/blogs/practicalsqldba/2012/03/15/importing-images-to-sql-server-database-using-t-sql/

In your case, you may want to adapt it slightly to match your KeyID with image name, but it should get you started.

Also check if you can implement a SSIS solution instead.

Also refer to forum post:
http://www.sqlservercentral.com/Forums/Topic1066764-391-1.aspx

HTH,

B
assefam
assefam
SSC Rookie
SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)SSC Rookie (33 reputation)

Group: General Forum Members
Points: 33 Visits: 210
Thank you very much for your reply.
Could you explain more about the SSIS solution possibilities?
bleroy
bleroy
SSC Veteran
SSC Veteran (258 reputation)SSC Veteran (258 reputation)SSC Veteran (258 reputation)SSC Veteran (258 reputation)SSC Veteran (258 reputation)SSC Veteran (258 reputation)SSC Veteran (258 reputation)SSC Veteran (258 reputation)

Group: General Forum Members
Points: 258 Visits: 739
You could possibly create a SSIS package to load the data/images into your table using foreach elements.

But this is really only worthwhile if this is going to be a recurring task (and possibly if the people who will be using the process prefer to use a graphical UI to apply changes to the script).
It may also be useful for the point of view of metadata, logging etc as it is (for the most part) built into SSIS - i.e. it's relatively straightforward to add logging into a SSIS package, whilst the pure T-SQL approach would require you to built your logging mechanisms - the same applies to some extent to the error handling.
Additionally, SSIS uses memory quite efficiently so that may be a benefit.

But if your ETL is mostly E and L (or just Load in your case), with very little T, and if you can write your SPs so they don't rely on cursors, then going the SP-only route will probably be fine.

HTH,

B
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search