You are here:Home » tsql » Example to insert image in table

Example to insert image in table

–Create Table
CREATE TABLE [dbo].[ImageTest](
[ID] [int] IDENTITY(1,1) NOT NULL,
[Image] [varbinary](MAX) NULL
) ON [PRIMARY]
GO

–Insert Image
INSERT INTO [dbo].[ImageTest]([Image])
SELECT * FROM
OPENROWSET(BULK N’C:\ImageCode\sa.jpg’, SINGLE_BLOB) AS Document
GO

–Clean Up DB
DROP TABLE [dbo].[ImageTest]
GO