WEB开发网      婵犵數濞€濞佳囧磹婵犳艾鐤炬い鎰堕檮閸嬬喐銇勯弽銊с€掗梻鍕閺岋箑螣娓氼垱笑闂佽姘﹂褔婀佸┑鐘诧工妤犲憡绂嶉崜褏纾奸弶鍫涘妼缁楁岸鏌熷畡鐗堝殗闁诡喒鏅犲畷褰掝敃閵堝棙顔忔繝鐢靛仦閸ㄥ爼骞愰幘顔肩;闁规崘绉ぐ鎺撳亹闁绘垶锕╁Λ鍕⒑閹肩偛濡奸悗娑掓櫇缁顓兼径妯绘櫇闂佹寧绻傞弻濠囨晝閸屾稓鍘甸柣搴㈢⊕閿氶柣蹇ョ稻缁绘繃绻濋崘銊т紝闂佽鍨伴崯鏉戠暦閻旂⒈鏁傞柛鈾€鏅欑槐妯衡攽閻愬樊鍤熷┑顔藉劤铻為柛鏇ㄥ墯閸欏繘鏌嶉崫鍕櫣缂佲偓婢跺绠鹃柟瀛樼箘閿涘秵顨ラ悙顏勭伈闁诡喖缍婂畷鎯邦槻婵℃彃顭烽弻娑㈠Ω閵夈儺鍔夌紓浣稿€哥粔褰掑极閹剧粯鏅搁柨鐕傛嫹 ---闂傚倷鐒︾€笛兠洪埡鍛闁跨噦鎷�
开发学院数据库MSSQL Server MS SQL SERVER 图像或大文本的输入输出 阅读

MS SQL SERVER 图像或大文本的输入输出

 2007-11-11 11:54:14 来源:WEB开发网 闂傚倷绶氬ḿ褍螞閹绢喖绠柨鐕傛嫹闂傚倷绀侀幉锟犲垂閻㈠灚宕查柟鎵閸庡秵銇勯幒鎴濃偓鐢稿磻閹炬枼妲堟繛鍡楃С濞岊亞绱撻崒姘扁枌闁瑰嚖鎷�婵犵數濮幏鍐川椤撴繄鎹曢梻渚€娼уú銈吤洪妸鈺佺劦妞ゆ帊鑳堕埊鏇㈡煏閸モ晛浠х紒杈╁仱閺佹捇鏁撻敓锟�闂傚倷绶氬ḿ褍螞閹绢喖绠柨鐕傛嫹  闂傚倷鑳舵灙缂佺粯顨呴埢宥夊即閵忕姵鐎梺缁樺姈椤愮厧鈽夊Ο閿嬬€婚梺褰掑亰閸撴稑鈻斿鑸碘拺闁告稑饪村▓鏃€绻涚仦鍌氬闁崇粯鎹囬獮瀣攽閹邦剚顔傛俊鐐€栧濠氬储瑜忛幉鎾晸閿燂拷
核心提示:在MS sql server(WINDOWS平台上强大的数据库平台) 安装目录下有个可执行文件叫 TEXTCOPY.EXE 可对 MS sql server(WINDOWS平台上强大的数据库平台) 中的文本或图像数据进行输入输出. 不过你可以在MS-DOS方式下执行textcopy /? 得到它的描述, 下面是这个工具

在MS sql server(WINDOWS平台上强大的数据库平台) 安装目录下有个可执行文件叫 TEXTCOPY.EXE
可对 MS sql server(WINDOWS平台上强大的数据库平台) 中的文本或图像数据进行输入输出.
不过你可以在MS-DOS方式下执行textcopy /? 得到它的描述。
下面是这个工具的描述:
Copies a single text or image value into or out of sql server(WINDOWS平台上强大的数据库平台). The val
ue
is a specified text or image 'column' of a single row (specified by th
e
"where clause") of the specified 'table'. 

If the direction is IN (/I) then the data from the specified 'file' is

copied into sql server(WINDOWS平台上强大的数据库平台), replacing the existing text or image value. If
the
direction is OUT (/O) then the text or image value is copied from
sql server(WINDOWS平台上强大的数据库平台) into the specified 'file', replacing any existing file.

TEXTCOPY [/S ][sqlserver]] [/U [login]] [/P ][password]]
  [/D ][database]] [/T table] [/C column] [/W"where clause"]
  [/F file] [{/I | /O}] [/K chunksize] [/Z] [/?]

  /S sqlserver    The sql server(WINDOWS平台上强大的数据库平台) to connect to. If 'sqlserver' is n
ot
           specified, the local sql server(WINDOWS平台上强大的数据库平台) is used.
  /U login      The login to connect with. If 'login' is not spec
ified,
           a trusted connection will be used.
  /P password     The password for 'login'. If 'password' is not
           specified, a NULL password will be used.
  /D database     The database that contains the table with the tex
t or
           image data. If 'database' is not specified, the d
efault
           database of 'login' is used.
  /T table      The table that contains the text or image value.

  /C column      The text or image column of 'table'.
  /W "where clause"  A complete where clause (including the WHERE keyw
ord)
           that specifies a single row of 'table'.
  /F file       The file name.
  /I         Copy text or image value into sql server(WINDOWS平台上强大的数据库平台) from 'fi
le'.
  /O         Copy text or image value out of sql server(WINDOWS平台上强大的数据库平台) into '
file'.
  /K chunksize    Size of the data transfer buffer in bytes. Minimu
m
           value is 1024 bytes, default value is 4096 bytes.

  /Z         Display debug information while running.
  /?         Display this usage information and exit.

You will be prompted for any required options you did not specify.

为此, 可写一个存储过程,调用这个命令
CREATE PROCEDURE sp_textcopy (
  @srvname   varchar (30),
  @login    varchar (30),
  @password   varchar (30),
  @dbname    varchar (30),
  @tbname    varchar (30),
  @colname   varchar (30),
  @filename   varchar (30),
  @whereclause varchar (40),
  @direction  char(1))
AS
DECLARE @exec_str varchar (255)
SELECT @exec_str =
     'textcopy /S ' + @srvname +
     ' /U ' + @login +
     ' /P ' + @password +
     ' /D ' + @dbname +
     ' /T ' + @tbname +
     ' /C ' + @colname +
     ' /W "' + @whereclause +
     '" /F ' + @filename +
     ' /' + @direction
EXEC master..xp_cmdshell @exec_str

下面是一个拷贝图像到sql server(WINDOWS平台上强大的数据库平台)的pubs数据库的例子, 表名pub_info, 字段名
logo,图像文件名picture.bmp,保存到pub_id='0736'记录 sp_textcopy @srvn
ame = 'ServerName',
       @login = 'Login',
       @password = 'Password',
       @dbname = 'pubs',
       @tbname = 'pub_info',
       @colname = 'logo',
       @filename = 'c:\picture.bmp',
       @whereclause = " WHERE pub_id='0736' ",
       @direction = 'I'

Tags:MS SQL SERVER

编辑录入:coldstar [复制链接] [打 印]
赞助商链接