Sybase exports BCP out table fields in a certain order

Source: Internet
Author: User
Tags sybase

Current requirement: there is a table A in the database, and table A has four columns: C1 C2 C3 C4; three fields of C1, C2, and C3 for all records in, sort by C1 C2 and export it to the data file.

Specific analysis: Because the SQL statement cannot be added after the BCP in Sybase, you cannot use the BCP out select C1, C2, C4 from a order by C1, C2Method.

Solution:

1. Change the Locking Scheme of Table A to allpages.


       
        ALTER TABLE A LOCK ALLPAGES
       

2. Create a clustered index on the C1 C2 column of Table.


       
        CREATE CLUSTERED INDEX aindex ON A(c1,c2)
       

3. Create a view that only contains column C1 C2 C3 of column


       
        create view aview as select c1,c2,c3 from a
       

4. BCP export View


       
        bcp aview out aview.data -c -t'|' -Uuser -Ppassword -Sserver >aview.log
       

Summary:

1. Use clustered indexes to forcibly limit the physical sequence of records in table.

2. Use the view to select the fields to be exported.

3. the BCP out view is to export data in the physical order recorded in the table.

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.