> ## Documentation Index
> Fetch the complete documentation index at: https://private-7c7dfe99-fix-nav-issues.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> EXCHANGE SQL 문에 대한 문서

# EXCHANGE SQL 문

두 개의 테이블 또는 딕셔너리의 이름을 원자적으로 교환합니다.
이 작업은 임시 이름을 사용하는 [`RENAME`](/ko/reference/statements/rename) 쿼리로도 수행할 수 있지만, 이 경우에는 원자적으로 처리되지 않습니다.

<Note>
  `EXCHANGE` 쿼리는 [`Atomic`](/ko/reference/engines/database-engines/atomic) 및 [`Shared`](/ko/products/cloud/features/infrastructure/shared-catalog#shared-database-engine) 데이터베이스 엔진에서만 지원됩니다.
</Note>

**구문**

```sql theme={null}
EXCHANGE TABLES|DICTIONARIES [db0.]name_A AND [db1.]name_B [ON CLUSTER cluster]
```

<div id="exchange-tables">
  ## EXCHANGE TABLES
</div>

두 테이블의 이름을 서로 교환합니다.

**구문**

```sql theme={null}
EXCHANGE TABLES [db0.]table_A AND [db1.]table_B [ON CLUSTER cluster]
```

<div id="exchange-multiple-tables">
  ### 여러 테이블 EXCHANGE
</div>

쉼표로 구분하면 하나의 쿼리에서 여러 쌍의 테이블을 EXCHANGE할 수 있습니다.

<Note>
  여러 쌍의 테이블을 EXCHANGE할 때는 **원자적으로가 아니라 순차적으로** 수행됩니다. 작업 중 오류가 발생하면 일부 테이블 쌍만 EXCHANGE되고 다른 테이블 쌍은 EXCHANGE되지 않을 수 있습니다.
</Note>

**예시**

```sql title="Query" theme={null}
-- 테이블 생성
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 TABLES a AND b, c AND d;

SHOW TABLE a;
SHOW TABLE b;
SHOW TABLE c;
SHOW TABLE d;
```

```sql title="Response" theme={null}
-- 이제 테이블 'a'는 'b'의 구조를 가지며, 테이블 'b'는 'a'의 구조를 가집니다
┌─statement──────────────┐
│ CREATE TABLE default.a↴│
│↳(                     ↴│
│↳    `b` UInt8         ↴│
│↳)                     ↴│
│↳ENGINE = Memory        │
└────────────────────────┘
┌─statement──────────────┐
│ CREATE TABLE default.b↴│
│↳(                     ↴│
│↳    `a` UInt8         ↴│
│↳)                     ↴│
│↳ENGINE = Memory        │
└────────────────────────┘

-- 이제 테이블 'c'는 'd'의 구조를 가지며, 테이블 'd'는 'c'의 구조를 가집니다
┌─statement──────────────┐
│ CREATE TABLE default.c↴│
│↳(                     ↴│
│↳    `d` UInt8         ↴│
│↳)                     ↴│
│↳ENGINE = Memory        │
└────────────────────────┘
┌─statement──────────────┐
│ CREATE TABLE default.d↴│
│↳(                     ↴│
│↳    `c` UInt8         ↴│
│↳)                     ↴│
│↳ENGINE = Memory        │
└────────────────────────┘
```

<div id="exchange-dictionaries">
  ## EXCHANGE DICTIONARIES
</div>

두 딕셔너리의 이름을 서로 교환합니다.

**구문**

```sql theme={null}
EXCHANGE DICTIONARIES [db0.]dict_A AND [db1.]dict_B [ON CLUSTER cluster]
```

**관련 항목**

* [딕셔너리](/ko/reference/statements/create/dictionary)
