> ## Documentation Index
> Fetch the complete documentation index at: https://clickhouse.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

> CREATE NAMED COLLECTION 参考文档

# CREATE NAMED COLLECTION

创建新的命名集合。

<Note>
  部分 ClickHouse Cloud 服务可启用通过 DDL 创建的命名集合。请联系 Support 确认可用性。
</Note>

**语法**

```sql theme={null}
CREATE [OR REPLACE] NAMED COLLECTION [IF NOT EXISTS] name [ON CLUSTER cluster] AS
key_name1 = 'some value' [[NOT] OVERRIDABLE],
key_name2 = 'some value' [[NOT] OVERRIDABLE],
key_name3 = 'some value' [[NOT] OVERRIDABLE],
...
```

`OR REPLACE` 与 `IF NOT EXISTS` 不能同时使用。对已存在的命名集合执行 `CREATE OR REPLACE`
会将其整体替换：新定义中未包含的键及可覆盖性标志都将被移除。

使用命名集合时，若要覆盖其中存储的键，需要拥有该集合的 `SHOW NAMED COLLECTIONS SECRETS` 特权，
即使键已标记为 `OVERRIDABLE` 也不例外。标记为 `NOT OVERRIDABLE` 的键无法被覆盖。
字典源同样遵循此规则。系统会在创建、附加或恢复字典时检查该特权。
而在加载字典时，仅对标记为 `NOT OVERRIDABLE` 的键强制执行限制。

**示例**

```sql theme={null}
CREATE NAMED COLLECTION foobar AS a = '1', b = '2' OVERRIDABLE;
CREATE OR REPLACE NAMED COLLECTION foobar AS a = '2', c = '3';
```

**相关语句**

* [ALTER NAMED COLLECTION](/docs/zh/reference/statements/alter/named-collection)
* [DROP NAMED COLLECTION](/docs/zh/reference/statements/drop#drop-function)

**另请参阅**

* [命名集合指南](/docs/zh/concepts/features/configuration/server-config/named-collections)

**属于：** `CREATE`
