Exchanges the names of two tables or dictionaries atomically.
This task can also be accomplished with a RENAME query using a temporary name, but the operation is not atomic in that case.
Syntax
EXCHANGE TABLES|DICTIONARIES [db0.]name_A AND [db1.]name_B [ON CLUSTER cluster]EXCHANGE TABLES
Exchanges the names of two tables.
Syntax
EXCHANGE TABLES [db0.]table_A AND [db1.]table_B [ON CLUSTER cluster]EXCHANGE MULTIPLE TABLES
You can exchange multiple table pairs in a single query by separating them with commas.
Example
-- Create tables
CREATE TABLE a (a UInt8) ENGINE=Memory;
CREATE TABLE b (b UInt8) ENGINE=Memory;
CREATE TABLE c (c UInt8) ENGINE=Memory;
CREATE TABLE d (d UInt8) ENGINE=Memory;
-- Exchange two pairs of tables in one query
EXCHANGE TABLES a AND b, c AND d;
SHOW TABLE a;
SHOW TABLE b;
SHOW TABLE c;
SHOW TABLE d;-- Now table 'a' has the structure of 'b', and table 'b' has the structure of 'a'
┌EXCHANGE DICTIONARIES
Exchanges the names of two dictionaries.
Syntax
EXCHANGE DICTIONARIES [db0.]dict_A AND [db1.]dict_B [ON CLUSTER cluster]See Also