如何使用 sql server management studio 将 blob 插入到数据库中

2022-01-01 00:00:00 sql blob sql-server-2005 sql-server

如何轻松地将 blob 插入 varbinary(MAX) 字段?

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

举个例子:

我想插入的是:c:picture.png
该表是 mytable
该列是 mypictureblob
这个地方是 recid=1

thing I want to insert is: c:picture.png
the table is mytable
the column is mypictureblob
the place is recid=1

推荐答案

您可以在 SQL Server Management Studio 中使用 T-SQL 插入 varbinary(max) 字段,尤其是使用 OPENROWSET 命令.

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

例如:

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

查看以下文档以获得一个很好的示例/演练

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

使用大值类型

请注意,在这种情况下,文件路径相对于目标 SQL 服务器,而不是您的客户端运行此命令.

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

相关文章