EXCHANGE
EXCHANGE
두 테이블 또는 딕셔너리의 이름을 원자적으로 교환해요.
이 작업은 임시 이름을 사용한 RENAME 쿼리로도 수행할 수 있지만, 그 경우 연산은 원자적이지 않아요.
EXCHANGE 쿼리는 Atomic 및 Shared 데이터베이스 엔진에서만 지원됩니다.
출처: 문서
본문
Syntax
EXCHANGE TABLES|DICTIONARIES [db0.]name_A AND [db1.]name_B [ON CLUSTER cluster]
EXCHANGE TABLES
두 테이블의 이름을 교환해요.
Syntax
EXCHANGE TABLES [db0.]table_A AND [db1.]table_B [ON CLUSTER cluster]
EXCHANGE MULTIPLE TABLES
단일 쿼리에서 쉼표로 구분하여 여러 테이블 쌍을 교환할 수 있어요.
여러 테이블 쌍을 교환할 때 교환은 원자적으로가 아니라 순차적으로 수행됩니다. 연산 중 오류가 발생하면 일부 테이블 쌍은 교환되었지만 다른 쌍은 교환되지 않았을 수 있어요.
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'
┌─statement──────────────┐
│ CREATE TABLE default.a↴│
│↳( ↴│
│↳ `b` UInt8 ↴│
│↳) ↴│
│↳ENGINE = Memory │
└────────────────────────┘
┌─statement──────────────┐
│ CREATE TABLE default.b↴│
│↳( ↴│
│↳ `a` UInt8 ↴│
│↳) ↴│
│↳ENGINE = Memory │
└────────────────────────┘
-- Now table 'c' has the structure of 'd', and table 'd' has the structure of 'c'
┌─statement──────────────┐
│ CREATE TABLE default.c↴│
│↳( ↴│
│↳ `d` UInt8 ↴│
│↳) ↴│
│↳ENGINE = Memory │
└────────────────────────┘
┌─statement──────────────┐
│ CREATE TABLE default.d↴│
│↳( ↴│
│↳ `c` UInt8 ↴│
│↳) ↴│
│↳ENGINE = Memory │
└────────────────────────┘
EXCHANGE DICTIONARIES
두 딕셔너리의 이름을 교환해요.
Syntax
EXCHANGE DICTIONARIES [db0.]dict_A AND [db1.]dict_B [ON CLUSTER cluster]
See Also