Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Query to import multiple image file to SQL server 2008 Database Expand / Collapse
Author
Message
Posted Thursday, November 8, 2012 3:32 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, November 27, 2012 12:00 AM
Points: 23, 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
Post #1382370
Posted Thursday, November 8, 2012 3:43 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, September 25, 2014 2:03 AM
Points: 167, Visits: 690
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

Post #1382375
Posted Friday, November 9, 2012 3:05 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, November 27, 2012 12:00 AM
Points: 23, Visits: 210
Thank you very much for your reply.
Could you explain more about the SSIS solution possibilities?
Post #1382911
Posted Friday, November 9, 2012 4:55 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, September 25, 2014 2:03 AM
Points: 167, Visits: 690
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
Post #1382961
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse