5. Populating Tables : COPY Statement Syntax : COPY INTO (Unload Data) and COPY FROM (Load Data)
 
Share this page                  
COPY INTO (Unload Data) and COPY FROM (Load Data)
The COPY statement is bidirectional; it unloads data from a table and loads data into a table.
The INTO and FROM keywords specify the direction of data movement:
The COPY INTO statement performs the unload operation, copying the data into a file from the database. For example, the following statement unloads the horx table into the pers.data file:
COPY TABLE horx (name=CHAR(20)COMMA, code=TEXT(0)NL)
INTO 'pers.data';
The COPY FROM statement performs the reload operation, copying the data from a file into the database. For example, the following statement loads the agent table from the myfile.in data file:
COPY TABLE agent (ano=CHAR(0)CSV, code=CHAR(0)CSV)
FROM 'myfile.in';
A common use of COPY is to unload a table for backup to tape or for transfer to another database. In either case, there is the possibility of reloading the data into a database later.