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

后端 未结 6 1159
暗喜
暗喜 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

    There are two ways to SELECT a BLOB with TSQL:

    SELECT * FROM OPENROWSET (BULK 'C:\Test\Test1.pdf', SINGLE_BLOB) a
    

    As well as:

    SELECT BulkColumn FROM OPENROWSET (BULK 'C:\Test\Test1.pdf', SINGLE_BLOB) a
    

    Note the correlation name after the FROM clause, which is mandatory.

    You can then this to INSERT by doing an INSERT SELECT.

    You can also use the second version to do an UPDATE as I described in How To Update A BLOB In SQL SERVER Using TSQL .

提交回复
热议问题