Share via


how to insert image into sql server manually (without code)

Question

Sunday, February 22, 2009 1:11 PM

Can someone please tell me how to insert image into SQL server 2005 manually - without code.

I'm set the field as data type "image" and tried classical copy paste method, but without result.

thanks

All replies (6)

Sunday, February 22, 2009 3:06 PM ✅Answered | 3 votes

You need code, if not client code then at least SQL Server code:

INSERT INTO YourSchema.YourTable   
(  
  ImageColumn  
)  
SELECT  *  
      * FROM OPENROWSET  
      ( BULK 'C:\YourPics\ThePic.jpg',SINGLE_CLOB) 

For more information have a look on:

http://msdn.microsoft.com/en-us/library/ms175915.aspx

Jens K. Suessmeyer


Sunday, February 22, 2009 3:10 PM ✅Answered | 2 votes

Check this code  from BOL :

USE AdventureWorks 
GO 
CREATE TABLE myTable(FileName nvarchar(60), FileType nvarchar(60), Document varbinary(max))
 GO
 INSERT INTO myTable(FileName, FileType, Document) 
SELECT 'Text1.txt' AS FileName, '.txt' AS FileType, * FROM 
OPENROWSET(BULK N'C:\Text1.txt', SINGLE_BLOB) AS Document
 GO

for More info : http://msdn.microsoft.com/en-us/library/ms190312.aspx









Madhu

MCITP, MCTS, MCDBA,MCP-- Blog : http://experiencing-sql-server-2008.blogspot.com/


Sunday, February 22, 2009 6:50 PM | 1 vote

Ok

Thanks very much for yours answers.

I hope that I will solve my problem successfully.

Once again, thanks for your help.


Wednesday, April 13, 2011 5:09 PM

hi,

can you please tell how to retrieve the data stored in that text file which we saved into the table.....

what if i delete the text file...?

how about if it is a image file

 

thanks.....


Tuesday, May 27, 2014 5:29 AM

hi, thank u for code

bt it dosen't work without alias

so it must be declare like this:

SELECT  *  
       FROM OPENROWSET  
      ( BULK 'C:\YourPics\ThePic.jpg',SINGLE_CLOB)  as photo

Tuesday, May 27, 2014 2:16 PM | 1 vote

Import/Export images and binary objects:

http://www.sqlusa.com/bestpractices/imageimportexport/

Kalman Toth Database & OLAP Architect SQL Server 2014 Design & Programming
**New Book / Kindle: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2016
**