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.