EXCHANGE statement

The EXCHANGE statement switches the content of a base table and its associated clone table.

Invocation for EXCHANGE

This statement can be embedded in an application program or issued interactively. It is an executable statement that can be dynamically prepared only if DYNAMICRULES RUN behavior is in effect. For more information, see Authorization IDs and dynamic SQL.

Authorization for EXCHANGE

The privilege set that is defined below must include at least one of the following privileges:

  • The INSERT and DELETE privileges on both the base table and the clone table
  • Ownership of the both the base table and the clone table
  • DBADM authority for the database
  • SYSADM authority
  • DATAACCESS authority

Privilege set: If the statement is embedded in an application program, the privilege set is the privileges that are held by the owner of the plan or package. If the statement is dynamically prepared, the privilege set is the union of the privilege sets that are held by each authorization ID of the process.

Syntax for EXCHANGE

Read syntax diagramSkip visual syntax diagramEXCHANGE DATA BETWEEN TABLE table-name1ANDtable-name2

Description for EXCHANGE

table-name1 and table-name2
Identifies the base table and the associated clone table for which the exchange of data will take place. Either table-name1 or table-name2 can identify the base table. The other table name must identify a clone table that is associated with the specified base table. The name of the base table and the name of the clone table remain unchanged after a data exchange.

Notes for EXCHANGE

Committing after EXCHANGE
Start of changeA commit is required before accessing a table after the EXCHANGE statement and between consecutive data exchanges using the EXCHANGE statement.End of change
Table partitions
Data exchanges cannot be done for a subset of table partitions.
Start of changePackage rebinds might be neededEnd of change
Start of changeYou might need to rebind packages that reference the base or clone tables before the applications can pick up the exchanged data. For more information, see Changes that might require package rebinds.End of change

Example for EXCHANGE

Exchange the data of the EMPLOYEE table and its clone table, EMPCLONE.
   EXCHANGE DATA BETWEEN TABLE EMPCLONE AND EMPLOYEE;