如何使用 TSQL 将文件上传到 SQL Server 2008 中的 varbinary(max) 列? [英] How do I upload a file to a varbinary(max) column in SQL Server 2008, using TSQL?

查看:29
本文介绍了如何使用 TSQL 将文件上传到 SQL Server 2008 中的 varbinary(max) 列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这一定是可能的,因为我相信我以前做过.这是我的查询:

This must be possible because I believe I've done it before. Here's my query:

insert into exampleFiles Values(NEWID(), cast('c:\filename.zip' as varbinary(max))

显然,这只是在引号之间插入文本,而不是该位置的文件.一定有我忘记的简单的 tsql 语言位.谢谢

Obviously that just inserts the text in between the quotes and not the file from that location. There must be a simple tsql bit of language that I'm forgetting. Thanks

推荐答案

这有帮助吗?

USE AdventureWorks
GO
CREATE TABLE myTable(FileName nvarchar(60),
  FileType nvarchar(60), Document varbinary(max))
GO

INSERT INTO myTable(FileName, FileType, field_varbinary)
   SELECT 'Text1.txt' AS FileName,
      '.txt' AS FileType,
      * FROM OPENROWSET(BULK N'C:\Text1.txt', SINGLE_BLOB) AS Document
GO

取自这里:http://social.msdn.microsoft.com/Forums/en-US/sqltools/thread/513cbf8c-21a8-4bcc-a565-6eb06437a398

这篇关于如何使用 TSQL 将文件上传到 SQL Server 2008 中的 varbinary(max) 列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆