Ad Code

How to Import Image File from File System to SQL Server Table

 How to Import Image File from File System to SQL Server Table - TSQL Tutorial

First and foremost, we need a column that can handle image files in order to save an image file in a SQL Server table. Pictures and other file types can be stored using the data type VARBINARY. Let's create a table with a variable datatype, then import an image using the script provided below.

 

CREATE TABLE dbo.TblPicture_Src (

 

 ID INT Identity(1, 1)

 

 ,NAME VARCHAR(100)

 

 ,Picture VARBINARY(MAX)

 

 )

 

GO

 

--Import Image/File from File System To SQL Server Table

 

INSERT INTO dbo.TblPicture_Src (

 

 NAME

 

 ,Picture

 

 )

 

SELECT 'Capture1.PNG'

 

 ,BulkColumn

 

FROM Openrowset(BULK 'C:\4_Mypicture.PNG', Single_Blob) AS Picture

 

SELECT *

 

FROM dbo.TblPicture_Src

 

 

 

 

Post a Comment

0 Comments

Close Menu