2022-02-15 01:53:21 +00:00
|
|
|
|
---
|
2022-08-26 19:07:59 +00:00
|
|
|
|
slug: /zh/sql-reference/statements/alter/constraint
|
2022-04-10 23:08:18 +00:00
|
|
|
|
sidebar_position: 43
|
|
|
|
|
sidebar_label: 约束
|
2022-02-15 01:53:21 +00:00
|
|
|
|
---
|
|
|
|
|
|
2022-02-15 01:56:25 +00:00
|
|
|
|
# 操作约束 {#manipulations-with-constraints}
|
2022-02-15 01:53:21 +00:00
|
|
|
|
|
2022-02-15 01:56:25 +00:00
|
|
|
|
约束可以使用以下语法添加或删除:
|
2022-02-15 01:53:21 +00:00
|
|
|
|
|
|
|
|
|
``` sql
|
2024-06-25 14:41:12 +00:00
|
|
|
|
ALTER TABLE [db].name [ON CLUSTER cluster] ADD CONSTRAINT [IF NOT EXISTS] constraint_name CHECK expression;
|
|
|
|
|
ALTER TABLE [db].name [ON CLUSTER cluster] DROP CONSTRAINT [IF EXISTS] constraint_name;
|
2022-02-15 01:53:21 +00:00
|
|
|
|
```
|
|
|
|
|
|
2022-08-29 17:59:51 +00:00
|
|
|
|
查看[constraints](../../../sql-reference/statements/create/table.mdx#constraints)。
|
2022-02-15 01:53:21 +00:00
|
|
|
|
|
2022-02-15 01:56:25 +00:00
|
|
|
|
查询将从表中添加或删除关于约束的元数据,因此它们将被立即处理。
|
2022-02-15 01:53:21 +00:00
|
|
|
|
|
2022-02-15 01:56:25 +00:00
|
|
|
|
!!! warning "警告"
|
|
|
|
|
如果已有数据被添加,约束检查**将不会被执行**。
|
2022-02-15 01:53:21 +00:00
|
|
|
|
|
2022-08-29 17:59:51 +00:00
|
|
|
|
复制表上的所有更改都会被广播到ZooKeeper,并应用到其他副本上。
|