sybasesqlanywheresybase-asa

How to use Sybase LOAD TABLE correctly?


I have been using ISQL (SQLAnywhere 12) to import data from CSVs into existing tables using INPUT INTO and never ran into a problem. Today I needed to import data into a table containing an auto-increment column, however, and thought I just needed to leave that column blank, so I tried it with a file containing only 1 row of data (to be safe). Turns out it imported with a 0 in the auto-increment field instead of the next integer value.

Looking at the Sybase documentation, it seems like I should be using LOAD TABLE instead, but the examples look a bit complex.

My questions are the following...

Many thanks in advance.


Solution

    1. Yes. Check out the online documentation for LOAD TABLE - you can use the USING CLIENT FILE clause.

    2. You can specify the column names in parens after the table name, i.e. LOAD TABLE mytable (col1, col2, col3) USING CLIENT FILE 'mylocalfile.txt'. Any columns not listed here will be set to NULL if the column is nullable or the equivalent to an empty string if it's not - this is why your autoincrement column was set to 0. You can use the DEFAULTS ON clause to get what you want.

    3. Yes, existing data in the table is not affected.