|
Execute the following
Microsoft SQL Server T-SQL administration script to export image into the file system from the database and import the image back into a table:
USE AdventureWorks;
-- export
DECLARE @SQLcommand NVARCHAR(4000)
SET @SQLcommand = 'bcp "select LargePhoto from AdventureWorks.Production.ProductPhoto
where ProductPhotoID = 111" queryout "f:\data\images\roadsterx.jpg" -T -n '
EXEC xp_cmdshell
@SQLcommand
GO
-- import image
INSERT Production.ProductPhoto
(ThumbnailPhoto,
ThumbnailPhotoFileName,
LargePhoto,
LargePhotoFileName)
SELECT NULL,
NULL,
LargePhoto.*,
N'roadsterx.jpg'
FROM OPENROWSET(BULK 'f:\data\images\roadsterx.jpg',SINGLE_BLOB) LargePhoto
GO
SELECT *
FROM Production.ProductPhoto
GO
Related article:
http://www.sqlusa.com/bestpractices/imageimportexport/
|