How to insert a blob into a database using sql server management studio

后端 未结 6 1166
暗喜
暗喜 2020-11-28 04:04

How can I easily insert a blob into a varbinary(MAX) field?

As an example:

thing I want to insert is: c:\\picture.png
the table is mytable

6条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-28 04:46

    You can insert into a varbinary(max) field using T-SQL within SQL Server Management Studio and in particular using the OPENROWSET commmand.

    For example:

    INSERT Production.ProductPhoto 
    (
        ThumbnailPhoto, 
        ThumbnailPhotoFilePath, 
        LargePhoto, 
        LargePhotoFilePath
    )
    SELECT ThumbnailPhoto.*, null, null, N'tricycle_pink.gif'
    FROM OPENROWSET 
        (BULK 'c:\images\tricycle.jpg', SINGLE_BLOB) ThumbnailPhoto
    

    Take a look at the following documentation for a good example/walkthrough

    Working With Large Value Types

    Note that the file path in this case is relative to the targeted SQL server and not your client running this command.

提交回复
热议问题