码迷,mamicode.com
首页 > 数据库 > 详细

如何向SQL SERVER 2008 插入图片数据

时间:2015-05-13 08:45:57      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:

最近在弄数据库,涉及到插入图片,但2008里已经不在支持TEXTCOPY, 需要用到openrowset.实际上个人认为这个更好用。以下从别处copy的例子

UPDATE and OPENROWSET can be used together to import an image into a table.

OPENROWSET can be used to import a file into a single row, single column value.

OPENROWSET
( BULK ‘data_file‘,| SINGLE_BLOB | SINGLE_CLOB | SINGLE_NCLOB )


Parameter      Description
data_file      The name and path of the file to read.
SINGLE_BLOB |      Designate the SINGLE_BLOB object for importing into a varbinary(max) data
SINGLE_CLOB |      type, SINGLE_CLOB for ASCII data into a varchar(max) data type, and
SINGLE_NCLOB      SINGLE_NCLOB for importing into a nvarchar(max) UNICODE data type.

Referenced from:
SQL Server 2005 T-SQL Recipes A Problem-Solution Approach
20>
21>
22> CREATE TABLE ImageTable(
23> ID int NOT NULL,
24> Gif varbinary(max) NOT NULL
25> )
26> GO
1>
2> INSERT ImageTable
3> (ID, Gif)
4> SELECT 1,
5> BulkColumn
6> FROM OPENROWSET(BULK ‘C:\yourImage.gif‘,SINGLE_BLOB) AS x
7> GO

1>
2> SELECT Gif
3> FROM ImageTable
4> WHERE ID = 1
5> GO

1>
2> UPDATE ImageTable
3> SET Gif =
4> (SELECT BulkColumn
5> FROM OPENROWSET(BULK
6> ‘C:\newImage.gif‘,
7> SINGLE_BLOB) AS x)
8> WHERE ID =1
9> GO

1>
2> drop table ImageTable
3> GO

 

如何向SQL SERVER 2008 插入图片数据

标签:

原文地址:http://www.cnblogs.com/jackyna127/p/4499298.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!