People asked me many times that “How to Store Images In SQL Server Table” So here i post a method which i explore recently from which we can store images in SQL Server Table……
On this post i just show you the way from which we can insert images in SQl Server Table…..
So here we start with Declare a Table in which images are storedso here we go by just creating a table….like..
CREATE TABLE [dbo].[ImageTest](
[ID] [int] IDENTITY(1,1) NOT NULL,
[Image] [varbinary](max) NULL
SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]
So by this we can create table with two columns one is identity and other image . Image column is varbinary (max) which stores the image in binary format…
So here is the code from which we can insert image in to this table …..
–Image Insert
INSERT INTO [dbo].[ImageTest]([Image])
SELECT * FROM
OPENROWSET(BULK N’D:\images1\image.jpg’, SINGLE_BLOB) AS Document
GO
Here D:\images1= Physical Path of Images OR Folder where images actually stored….
so in this way you can store images in your SQL Table..
u can see your data
– Check Data
select * from IMAGETEST
You have to ENABLE “Ad Hoc Remote Queries“ from your Sql Server Surface Area Configuration
OR USE
“Sp_Configure” to do so..
So here is the way from which you can store IMAGES in your SQL Table
This is only a way but from my opinion you just store only the physical path in your table and try to retrive Images in your application from your physical path,,,
but this is also a way to do so…
in my next post you will find how to retrive images from SQL Table i will show you the way that how u can retrive images from SQL table..
So jus keep watching….
Thanks and Happy Quering….
April 11, 2009 at 6:33 pm
[...] Posted by ashishgilhotra under SQL | Tags: BCP, Image retriveing | No Comments In my last post in tell you guys that how to insert images in any SQL Table so this is the post for ” How to [...]