Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert image into SQL Server [duplicate]

I want to insert in a table an (image , id, Code) but I don't know how to do this .

What I am looking for is how to insert an image not url.

like image 748
mitsu Avatar asked Feb 06 '14 10:02

mitsu


People also ask

How do I insert an image into SQL Server?

1) Bring up SQL Server Management Studio. 2) Connect, and open the database you want to add the image to. 3) Expand the tables, and either add a new table with an appropriate index field, or right click teh table and select design. 4) Add a field called "myImage", and make its datatype "image".

Can we store images in SQL Server database?

We can't store an image directly into the database. For this we have two solutions: To store the location of the image in the database. Converting the image into binary data and insert that binary data into database and convert that back to image while retrieving the records.


1 Answers

you can try like this

CREATE TABLE ImageTable
(
    Id int,
    Name varchar(50) ,
    Photo varbinary(max) 
)

INSERT INTO ImageTable (Id, Name, Photo) 
SELECT 1, 'test', BulkColumn 
FROM Openrowset( Bulk 'C:\test.jpg', Single_Blob) as image
like image 110
Pranay Rana Avatar answered Sep 23 '22 22:09

Pranay Rana