home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.3 (Developer) / NeXT_Developer-3.3.iso / usr / sybase / doc / bcp.man < prev    next >
Encoding:
Text File  |  1993-04-22  |  23.2 KB  |  551 lines

  1.  
  2.   1                       Version 4.0 -- 1/15/89                     bcp
  3.   ______________________________________________________________________
  4.  
  5.   NAME:  bcp
  6.  
  7.   FUNCTION:
  8.        Copies a database table to  or  from  a  host  file  in  a  user-
  9.        specified format.
  10.  
  11.   SYNTAX:
  12.        bcp [[database_name.]owner.]table_name {in | out} datafile
  13.        [-m maxerrors]  [-f formatfile] [-e errfile]
  14.        [-F firstrow]  [-L lastrow] [-b batchsize]
  15.        [-n] [-c]
  16.        [-t field-terminator] [-r row-terminator]
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.  
  24.   bcp                     Version 4.0 -- 1/15/89                       2
  25.   ______________________________________________________________________
  26.        [-U username] [-P password] [-I interface] [-S server] [-v]
  27.  
  28.   EXAMPLES:
  29.        In the following example, bcp copies  data  from  the  publishers
  30.        table  to  a  file for later reloading into SQL Server.  Defaults
  31.        were accepted for all prompts by pressing RETURN.
  32.  
  33.        bcp pubs..publishers out publ_out
  34.        Password:
  35.  
  36.        Enter the file storage type of field pub_id [char]:
  37.        Enter prefix-length of field pub_id [0]:
  38.        Enter length of field pub_id [4]:
  39.        Enter field terminator [none]:
  40.  
  41.        Enter the file storage type of field pub_name [char]:
  42.        Enter prefix-length of field pub_name [1]:
  43.  
  44.  
  45.  
  46.   3                       Version 4.0 -- 1/15/89                     bcp
  47.   ______________________________________________________________________
  48.        Enter length of field pub_name [40]:
  49.        Enter field terminator [none]:
  50.  
  51.        Enter the file storage type of field city [char]:
  52.        Enter prefix-length of field city [1]:
  53.        Enter length of field city [20]:
  54.        Enter field terminator [none]:
  55.  
  56.        Enter the file storage type of field state [char]:
  57.        Enter prefix-length of field state [1]:
  58.        Enter length of field state [2]:
  59.        Enter field terminator [none]:
  60.  
  61.        Do you want to save this format information in a file? [Y-n] y
  62.        Host filename [bcp.fmt]: pub_form
  63.  
  64.        Starting copy...
  65.  
  66.  
  67.  
  68.   bcp                     Version 4.0 -- 1/15/89                       4
  69.   ______________________________________________________________________
  70.  
  71.        3 rows copied.
  72.        Clock Time (ms.): total = 0   Avg = 0  (3.00 rows per sec.)
  73.  
  74.        The results go into publ_out.
  75.  
  76.        To copy this data back into SQL Server  using  the  saved  format
  77.        file, pub_form, you would use the command:
  78.  
  79.        bcp pubs..publishers in publ_out -f pub_form
  80.  
  81.  
  82.   PARAMETERS:
  83.        database_name -  is optional if the table being copied is in your
  84.            default  database.   Otherwise,  you  must specify a database
  85.            name.
  86.        owner -  is optional only if you own the table being copied.   If
  87.  
  88.  
  89.  
  90.   5                       Version 4.0 -- 1/15/89                     bcp
  91.   ______________________________________________________________________
  92.            no owner is specified and you do not  own  a  table  of  that
  93.            name, the command fails.
  94.        table_name -  the name of the database table you want to copy.
  95.        {in | out} -  the direction of the copy. In indicates a copy from
  96.            a file into the database table, while out is a copy to a file
  97.            from the database table.
  98.        datafile -  the full path name of a host file.  The path name can
  99.            be  from 1 to 255 characters in length.  It can also indicate
  100.            a tape drive name.
  101.        -m maxerrors -  the maximum number of errors before the  copy  is
  102.            aborted.   Each  row that can't be built by bcp is thrown out
  103.            and counted as one error.  The default, used if  this  option
  104.            is not included, is 10.
  105.        -f formatfile -  the  full  path  name  of  a  file  with  stored
  106.            responses from a previous use of bcp on the same table; crea-
  107.            tion of the format file is optional.  Use  this  option  only
  108.            when  you have already created a format file that you want to
  109.  
  110.  
  111.  
  112.   bcp                     Version 4.0 -- 1/15/89                       6
  113.   ______________________________________________________________________
  114.            use for a copy in or out.   After  you  answer  bcp's  format
  115.            questions,  it  will ask you if you want to save your answers
  116.            in a format file.  The default file name is bcp.fmt.  The bcp
  117.            program can refer to a format file when copying data, so that
  118.            you do not have to duplicate your previous  format  responses
  119.            interactively.   If  this  option is not used, bcp will query
  120.            you for format information interactively.
  121.        -e errfile -  the full path name  of  an  error  file  where  bcp
  122.            stores  any rows that it was unable to transfer from the file
  123.            to the database.  Error messages from the bcp program  go  to
  124.            the user's workstation.  If this option is not used, no error
  125.            file is created.
  126.        -F firstrow -  the number of the first row to  copy  (default  is
  127.            the first row).
  128.        -L lastrow -  the number of the last row to copy (default is  the
  129.            last row).
  130.        -b batchsize -  the number of rows per batch of data copied  (the
  131.  
  132.  
  133.  
  134.   7                       Version 4.0 -- 1/15/89                     bcp
  135.   ______________________________________________________________________
  136.            default is to copy all the rows in one batch).
  137.        -n -  perform the copy operation using the data's  native  (data-
  138.            base)  datatypes as the default.  This option does not prompt
  139.            for each field; it uses the default values.
  140.        -c -  perform the copy  operation  with  character  type  as  the
  141.            default.  This option does not prompt for each field; it uses
  142.            char as the default storage type,  no  prefixes,  \t  as  the
  143.            default  field  separator, and \n as the default row termina-
  144.            tor.
  145.        -t field-terminator -  specify the default field terminator.
  146.        -r row-terminator -  specify the default row terminator.
  147.        -U username -  allows the user to specify a login name.
  148.        -P password -  allows the user to specify a password.  If the  -P
  149.            option  is  not given, bcp prompts for a password.  If the -P
  150.            option is given at the end of the command  line  without  any
  151.            password, bcp uses the default password (NULL).
  152.        -I interface -  allows the user to specify the name and  location
  153.  
  154.  
  155.  
  156.   bcp                     Version 4.0 -- 1/15/89                       8
  157.   ______________________________________________________________________
  158.            of the interfaces file that can (optionally) be  searched  as
  159.            part  of  the  process  of connecting to the SQL Server.  The
  160.            named file contains the name and  network  address  of  every
  161.            available  SQL Server  on the network.  If this option is not
  162.            used, bcp looks for a file named interfaces.
  163.        -S  server -   allows  the  user  to  specify  the  name  of  the
  164.            SQL Server  with  which  to  connect.   This is the name that
  165.            SQL Server looks up in the interfaces file.
  166.        -v -  reports the current version of the bcp program.
  167.  
  168.   COMMENTS:
  169.  
  170.        o The bcp bulk copy program  provides  a  convenient  method  for
  171.          transferring  data  between a database table and a host file or
  172.          tape.  Data copied IN from a file is appended  to  an  existing
  173.          database table; data copied OUT to a file overwrites any previ-
  174.          ous contents of the file.
  175.  
  176.  
  177.  
  178.   9                       Version 4.0 -- 1/15/89                     bcp
  179.   ______________________________________________________________________
  180.        o The bcp program performs a high-speed  data  transfer.   It  is
  181.          capable  of  reading or writing files in a wide variety of for-
  182.          mats.
  183.  
  184.        o The -n (native format) and -c (character format)  command  line
  185.          options  each  provide  specific  default  formats for the data
  186.          being copied.  Native format provides the most compact storage;
  187.          character   format  creates  ASCII  files,  with  tabs  between
  188.          columns.
  189.        o When neither of the -n or -c option is used, bcp will query the
  190.          user  for  information  about  each  column  in the table to be
  191.          copied and asks whether you want to save your  format  informa-
  192.          tion in a file.
  193.  
  194.        o Upon completion, bcp informs you of the number of rows of  data
  195.          successfully  copied, the number of rows (if any) that it could
  196.          not copy, the total time the copy took, the average  amount  of
  197.          time  it  took to copy one row (given in milliseconds), and the
  198.  
  199.  
  200.   bcp                     Version 4.0 -- 1/15/89                      10
  201.   ______________________________________________________________________
  202.          number of rows copied per second.
  203.  
  204.        o In order to use bcp, you must have a valid  SQL Server  account
  205.          and  the  appropriate  permissions  on  the database tables and
  206.          files.
  207.        o The bcp program is optimized to load data into tables  that  do
  208.          not have indexes associated with them.  When you copy data into
  209.          a table that does have one or more indexes, a slower version of
  210.          bcp is automatically used.
  211.  
  212.          However, the fast version of bcp inserts data  without  logging
  213.          it,  and requires the System Administrator or Database Owner to
  214.          first  set  the  select  into/bulkcopy  option  on   with   the
  215.          sp_dboption  procedure.  If the option is not set on and a user
  216.          tries to copy data into a table that has no indexes, SQL Server
  217.          generates  an error message.  You don't need to set this option
  218.          in order to copy data out to a file, or in order to  copy  data
  219.  
  220.  
  221.  
  222.   11                      Version 4.0 -- 1/15/89                     bcp
  223.   ______________________________________________________________________
  224.          in to a table that does have indexes.  A bulk copy in to tables
  225.          that  have  indexes  always uses the slower version of bcp, and
  226.          row inserts are logged.
  227.  
  228.  
  229.          WARNING  ________________________________________________________
  230.          |                                                               |
  231.          |  Because bulk copy logs inserts  into  a  table  that  has    |
  232.          |  indexes,  the  log can grow very large.  You can truncate    |
  233.          |  the log with DUMP TRANsaction after the  bulk  copy  com-    |
  234.          |  pletes,  after you have backed up your database with DUMP    |
  235.          |  DATABASE.                                                    |
  236.          |_______________________________________________________________|
  237.  
  238.  
  239.     While  the select into/bulkcopy option is on, you are not allowed to
  240.     dump the transaction log.  Issuing the  DUMP  TRANsaction  statement
  241.     produces  an  error  message  instructing  you  to use DUMP DATABASE
  242.  
  243.  
  244.   bcp                     Version 4.0 -- 1/15/89                      12
  245.   ______________________________________________________________________
  246.     instead.
  247.  
  248.     This table shows which version of bcp will be used when copying  IN,
  249.     the  necessary  settings  for  the  select into/bulkcopy option, and
  250.     whether the transaction log is kept and dumpable.
  251.  
  252.                                            select into/bulkcopy
  253.                                              ON                OFF
  254.                fast bcp                      OK
  255.      (no indexes on target table)   DUMP TRAN prohibited    prohibited
  256.                slow bcp                      OK                 OK
  257.         (one or more indexes)       DUMP TRAN prohibited   DUMP TRAN OK
  258.  
  259.     By default, the select into/bulkcopy option is off in newly  created
  260.     databases.   To change the default situation, turn this option on in
  261.     the Model Database.
  262.  
  263.  
  264.  
  265.  
  266.   13                      Version 4.0 -- 1/15/89                     bcp
  267.   ______________________________________________________________________
  268.     The performance penalty for copying  data  into  a  table  that  has
  269.     indexes  in  place  may  be severe.  If you are copying in data that
  270.     will increase the size of the table by 25%, it may be faster to drop
  271.     all  the  indexes beforehand with DROP INDEX, copy the data into the
  272.     table, and then recreate the indexes.
  273.  
  274.  
  275.     WARNING  _____________________________________________________________
  276.     |                                                                    |
  277.     |  Your database must have free space equal to at least  120%  of    |
  278.     |  the size of the table in order to build or rebuild a clustered    |
  279.     |  index.                                                            |
  280.     |____________________________________________________________________|
  281.  
  282.  
  283.   o When  using  bcp, the user is prompted for a password, if it was not
  284.     supplied with the -P option.
  285.  
  286.  
  287.  
  288.   bcp                     Version 4.0 -- 1/15/89                      14
  289.   ______________________________________________________________________
  290.   o After the password has been given, bcp prompts  for  information  on
  291.     each  field  in the specified table.  Each prompt displays a default
  292.     value, in brackets, which is accepted by pressing  the  RETURN  key.
  293.     The  prompts  include:  the  storage  type a prefix-length the field
  294.     length a field terminator
  295.  
  296.   o The  defaults  in  brackets  at  each  prompt  represent  reasonable
  297.     defaults  for the field in question.  These default values depend on
  298.     the datatype of the field.  The following table shows  the  defaults
  299.     and possible responses.
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.   15                      Version 4.0 -- 1/15/89                     bcp
  311.   ______________________________________________________________________
  312.  
  313.          Prompt               Default Provided           Possible Responses
  314.     Storage Type     Database     storage               char  to  create  or
  315.                      type     for    most               read  an ASCII file;
  316.                      fields;                            any SQL Server data-
  317.                      char for varchar;                  type  where implicit
  318.                      binary   for    var-               conversion  is  sup-
  319.                      binary.                            ported.
  320.     Prefix Length    0 for fields defined with datatype 0 if  no  prefix  is
  321.                        (not storage type) char          desired;    defaults
  322.                        and all fixed-length datatypes,  are  recommended  in
  323.                      1 for most other datatypes         all other cases.
  324.                      2 for binary and varbinary
  325.                        saved as char
  326.                      4 for text and image
  327.  
  328.  
  329.  
  330.  
  331.  
  332.   bcp                     Version 4.0 -- 1/15/89                      16
  333.   ______________________________________________________________________
  334.     Length           Defined  length  for               Default  values,  or
  335.                      char   and  varchar.               greater,  are recom-
  336.                      Defined length  *  2               mended.
  337.                      for  binary and var-
  338.                      binary   saved    as
  339.                      char.        Maximum
  340.                      length   needed   to
  341.                      avoid  truncation or
  342.                      data  overflow   for
  343.                      all other datatypes.
  344.  
  345.  
  346.  
  347.  
  348.  
  349.  
  350.  
  351.  
  352.  
  353.  
  354.   17                      Version 4.0 -- 1/15/89                     bcp
  355.   ______________________________________________________________________
  356.     Field Terminator None.                              Up to 30 ASCII char-
  357.                                                         acters,  or  one  of
  358.                                                         the following:
  359.                                                          \t tab
  360.                                                          \n newline
  361.                                                          \r carriage return
  362.                                                          \0 null terminator
  363.                                                          \\ backslash
  364.  
  365.  
  366.   o Data can be copied into a file either as its native (database) data-
  367.     type,  or as any datatype for which implicit conversion is supported
  368.     for the datatype in question.  See the DB-Library  manual  page  for
  369.  
  370.  
  371.  
  372.  
  373.  
  374.  
  375.  
  376.   bcp                     Version 4.0 -- 1/15/89                      18
  377.   ______________________________________________________________________
  378.     dbconvert for details.
  379.  
  380.     Here are the default storage datatypes that correspond to SQL Server
  381.     datatypes, and the legal abbreviations:
  382.  
  383.        Table DatatypeStorageType
  384.  
  385.        char      c[har]
  386.        varchar   c[har]
  387.        text      T[ext]
  388.        binary    x
  389.        varbinary x
  390.        image     I[mage]
  391.        int       i[nt]
  392.        smallint  s[mallint]
  393.        tinyint   t[inyint]
  394.        float     f[loat]
  395.  
  396.  
  397.  
  398.   19                      Version 4.0 -- 1/15/89                     bcp
  399.   ______________________________________________________________________
  400.        bit       b[it]
  401.        money     m[oney]
  402.        datetime  d[ate]
  403.        timestamp x
  404.  
  405.        |-Brackets ([]) indicate that you may use the  initial  character,
  406.        or  the  beginning characters of the word, i.e. for bit you could
  407.        use b, bi or bit.
  408.  
  409.        timestamp data is treated as binary(8).
  410.  
  411.   o Fields defined in the database as char and binary are always  padded
  412.     with spaces to the full length defined in the database.
  413.   o When storing fields (except char and binary fields) as char  instead
  414.     of  their database datatypes, they will take less file storage space
  415.     with the default length and a prefix or a terminator.  bcp  can  use
  416.     either  a terminator or a prefix to determine the most efficient use
  417.  
  418.  
  419.  
  420.   bcp                     Version 4.0 -- 1/15/89                      20
  421.   ______________________________________________________________________
  422.     of storage space.  The maximum amount of storage space required  for
  423.     each field is suggested by bcp as the default.
  424.  
  425.     A length prefix is a 1, 2, or 4-byte integer  which  represents  the
  426.     length  of each data value, and immediately precedes each data value
  427.     in the host file.  A terminator is any character or string of  char-
  428.     acters.
  429.  
  430.     The tables below show the interaction  of  prefix-lengths,  termina-
  431.     tors,  and  field  length  on the information in the file.  ``P'' is
  432.     used to indicate the prefix in the stored table; ``T'' indicates the
  433.     terminator,  and  appended  spaces  are  shown  with  dashes, ``-''.
  434.     ``...'' indicates that the pattern would repeat for each field.  The
  435.     field length is 8 for each column, and we're storing the 6-character
  436.     field ``string'' each time.
  437.  
  438.     SQL Server char data
  439.  
  440.  
  441.  
  442.   21                      Version 4.0 -- 1/15/89                     bcp
  443.   ______________________________________________________________________
  444.  
  445.                       Prefix-length = 0     Prefix-length 1, 2 or 4
  446.     No terminator   string--string--...     Pstring--Pstring--...
  447.     Terminator      string--Tstring--T...   Pstring--TPstring--T...
  448.  
  449.  
  450.  
  451.     Other datatypes converted to char storage
  452.  
  453.                      Prefix-length = 0    Prefix-length 1, 2 or 4
  454.     No terminator   string--string--...   PstringPstring...
  455.     Terminator      stringTstringT...     PstringTPstringT...
  456.  
  457.   o Note that the file storage type and length of a column do  not  have
  458.     to  be the same as the type and length of the column in the database
  459.     table.  (If types and formats being copied in are incompatible  with
  460.     the structure of the database table, the copy fails.)
  461.  
  462.  
  463.  
  464.   bcp                     Version 4.0 -- 1/15/89                      22
  465.   ______________________________________________________________________
  466.  
  467.   o User datatypes are copied as their base datatype or as any  datatype
  468.     for which implicit conversion is supported.
  469.   o For char or varchar data, any length value is accepted.
  470.  
  471.   o If data in varchar and varbinary fields is longer  than  the  length
  472.     you specify for copy out, the data in the file is silently truncated
  473.     at the specified length.
  474.   o A terminator string can be up to 30 characters long; the most common
  475.     terminators  are  a  tab (entered as ``\t'' and used for all columns
  476.     except the last one), a newline (entered as ``\n'' and used for  the
  477.     last  field in a row).  Other terminators are: \0 (the null termina-
  478.     tor) and \\ (backslash) and \r (carriage return).
  479.  
  480.   o When a terminator or prefix is present, it affects the actual length
  481.     of  data transferred.  If the length of an entry being copied out to
  482.     a file is less than the storage length, it is  followed  immediately
  483.     by  the  terminator, or the prefix for the next field.  The entry is
  484.  
  485.  
  486.   23                      Version 4.0 -- 1/15/89                     bcp
  487.   ______________________________________________________________________
  488.     not padded to the full storage  length  (char  and  binary  data  is
  489.     returned from SQL Server already padded to the full length).
  490.  
  491.   o When copying in from a file, data is transferred  until  either  the
  492.     number  of  bytes  indicated  have  been copied or the terminator is
  493.     encountered.  Once a number of  bytes  equal  to  the  file  storage
  494.     length  has  been transferred, the rest of the data is flushed until
  495.     the terminator is encountered.  When  no  terminator  is  used,  the
  496.     table storage length is strictly observed.
  497.   o To determine the file storage length, a good rule  of  thumb  is  to
  498.     consider  it  to be the maximum amount of data to be transferred for
  499.     the column, plus terminators and/or prefixes.
  500.  
  501.   o When data is copied into a table, any defaults defined  for  columns
  502.     and  user  datatypes  are observed.  However, rules and triggers are
  503.     ignored in order to load data at the fastest possible speed.
  504.   o For the most efficient use of space when  copying  out  to  a  file,
  505.  
  506.  
  507.  
  508.   bcp                     Version 4.0 -- 1/15/89                      24
  509.   ______________________________________________________________________
  510.     accept the default prompts: copy all data in their table  datatypes,
  511.     use  prefixes  as  indicated, do not use terminators, and accept the
  512.     default lengths.
  513.  
  514.   o If you hand-created input scripts for use as format files with  pre-
  515.     4.0 bcp, you can use the bcptrans program to create new format files
  516.     for use with the new bcp.  The syntax of bcptrans is:
  517.  
  518.     bcptrans [[database_name.]owner.]table-name [ -3] {in | out} file_name [errors]
  519.  
  520.     The conversion program produces two files: bcptrans.cmd contains the
  521.     appropriate command line for the new bcp program.  bcptrans.fmt con-
  522.     tains the appropriate format file for the new bcp program.
  523.  
  524.   These two files can then be used as input to the new bcp.
  525.  
  526.   The -3 flag to bcptrans must be used to convert  an  old  format  file
  527.   when you are planning to copy IN an old datafile you created using the
  528.  
  529.  
  530.   25                      Version 4.0 -- 1/15/89                     bcp
  531.   ______________________________________________________________________
  532.   default type and length for float and datetime data.  (Otherwise,  the
  533.   format  file  bcptrans  creates  will  use the new default lengths for
  534.   float and datetime data, which have been changed from 20 characters to
  535.   25  characters for float, and 26 characters for datetime).  Do not use
  536.   the -3 flag for converting format files for any  data  that  does  not
  537.   match this specification.
  538.  
  539.   RETURNS:
  540.        This routine returns 0 upon successful completion.  Otherwise  it
  541.        returns 1.
  542.  
  543.  
  544.  
  545.  
  546.  
  547.  
  548.  
  549.  
  550.  
  551.