SQLUSA

Microsoft SQL Server 2000

Best Practices

 

How to import an image into a table?

 

This is not a simple operation. First you create an image table.

create table ClassicImage ([picture] image)

Second you setup a format file using bcp at command prompt. You have to respond to the prompts. You set the size of image the size of the image file you are about to import. You save the format file with name: e:\data\test\pubsimage.fmt

bcp pubs..classicimage out e:\data\test\classicimage1.dat -SPROD1 -Usa -P

Finally, you are ready to import in Query Analyzer:

use pubs

BULK INSERT ClassicImage FROM 'e:\design\photos\mydog1.jpg'
WITH (FORMATFILE = 'e:\data\test\pubsimage.fmt')


 

The World Leader in SQL Server Training
 
SQLUSA.com Home Page