Search code examples
exportexport-to-csvsybasesap-aseisql

How to export all tables within an Sybase 12.5 database to multiple flat files?


My customers runs an very old (seems to me) Sybase 12.5.2 database. I want/need to export all tables from a database to multiple (for each table) flat (text) files. I have access to ISQL command line prompt with the admin user. I havent worked ever with an Sybase database before.


Solution

  • Sybase Adaptive Server Enterprise (ASE) allows multiple databases to be hosted. You don't specify whether only one of the databases in the database server needs to be exported or if all of them do.

    For each database, the following query will list the names of the tables

    select name from sysobjects where type = 'U'
    

    Sybase ASE also comes with a tool called "bcp" which stands for "Bulk Copy". It is an easy way of creating a flat file of a table's contents.

    bcp database.schema.table out file_name -c -U username -S server_name
    

    It has more options that may be of interest, especially around field and row terminators. Documentation for the most relevant version (12.5.1) can be found here:

    http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.dc30191_1251/html/utility/BABGCCIC.htm