MS SQL SERVER image or large text input and output

Source: Internet
Author: User
Tags contains copy table name
Server

There is an executable file called Textcopy under the MS SQL SERVER installation directory. Exe
You can input and output text or image data in MS SQL SERVER.
But you can perform textcopy in MS-dos mode. Get a description of it.
The following is a description of the tool:
Copies a single text or image value in or out of SQL Server. 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, replacing the existing text or image value. If
The
Direction is out (/O) then the text or image value is copied from
SQL Server into the specified ' file ' and 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 SQL Server to. If ' SQL Server ' is n
ot
specified, the local SQL Server is used.
/U Login The login to connect with. If ' login ' is not spec
Ified,
A trusted connection would be used.
/P Password The password for ' login '. If ' password ' is not
specified, a NULL password would be used.
/D Database The database that contains the table with the Tex
T or
image data. If ' database ' isn't specified, the D
efault
Database of ' login ' is used. The
/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 is specifies a single row of ' table '.
/f File The file name.
/I Copy text or image value into SQL Server from ' fi
Le '.
/o Copy text or image value out of SQL Server into '
File '.
/k chunksize Size of the data transfer buffer in bytes. Minimu
M
The value is 1024 bytes, the default value is 4096 bytes.

/z Display Debug information while running.
/? Display This usage information and exit.

You are prompted for any required options to you did not specify.

To do this, you can write a stored procedure that invokes this command
CREATE PROCEDURE sp_textcopy (
@srvname varchar,
@login varchar,
@passwor D varchar,
@dbname varchar,
@tbname varchar (a),
@colname varchar (a),
@filename varchar (30),
@whereclause varchar,
@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

Here is an example of the pubs database that copies images to SQL Server, table name pub_info, field name
Logo, image filename picture.bmp, save to Pub_id= ' 0736 ' record 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 '



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.