How to store image in SQL Server database tables column
292,800
give this a try,
insert into tableName (ImageColumn)
SELECT BulkColumn
FROM Openrowset( Bulk 'image..Path..here', Single_Blob) as img
INSERTING
REFRESHING THE TABLE
Author by
VINNUSAURUS
Updated on December 14, 2020Comments
-
VINNUSAURUS over 3 years
I Have a table named
FEMALE
in my database. It hasID
asPrimary Key
, it has anImage
column.My Question is how do I store an image using a SQL Query?
-
VINNUSAURUS about 11 yearsPlease explain what is bulkcolumn ?
-
John Woo about 11 years
bulkcolumn
is part of the syntax. -
VINNUSAURUS about 11 yearsI Tried this INSERT INTO Female (Image) SELECT BulkColumn FROM Openrowset(BULK 'E:\Vinay\New Folder (2)\ileana00002.jpg ',Single_Blob)as img , but it is giving error Msg 515, Level 16, State 2, Line 1 Cannot insert the value NULL into column 'ID', table 'PMB.dbo.Female'; column does not allow nulls. INSERT fails. The statement has been terminated.
-
John Woo about 11 yearsthe reason for that is your column
ID
is a NON_NULLABLE column. is it an integer column and set as identity? if not, then you need to specifically define column in yourINSERT
statement. -
VINNUSAURUS about 11 yearsPlease show me how to do that iam new to SQL and i need it immediatly.
-
VINNUSAURUS about 11 yearsmy ID column is PK and incriments 1 on each entry
-
VINNUSAURUS about 11 yearsOOPS THANK YOU it worked :D i did not set identity incriment and seeding property for auto incriment, but it worked thanks for the help :)
-
VINNUSAURUS about 11 yearsCan you please show me how to insert other column Details too with the above query, that is with the image how to insert into other rows at the same time ?
-
John Woo about 11 years
-
Ads almost 11 years@JW웃 what is the format its stored in the image column? is it Base64 or any other format?
-
Ali.Rashidi over 7 yearswhen I use WHERE in the query to insert image to specified rows it does not recognize table column names. why?
-
dosaki over 6 yearsThe path needs to be local to the machine holding SQL Server