DROP CONSTRAINT 语句ALTER TABLE 的一部分,会删除 列Check 和 Foreign Key 约束.

Note: 关于其他约束的删除, 请看 Constraints: Remove Constraints.

概要

图片

所需权限

用户必须拥有要操作表的 CREATE 权限

参数

Parameter Description
table_name 要删除约束的表名
name 要删除约束的列的名字

查看结构变化

当我们变更表结构时,CockroachDB会把这个操作注册成一个job,可以通过SHOW JOBS查看。

例子

> SHOW CONSTRAINTS FROM orders;
+--------+---------------------------+-------------+-----------+----------------+
| Table  |           Name            |    Type     | Column(s) |    Details     |
+--------+---------------------------+-------------+-----------+----------------+
| orders | fk_customer_ref_customers | FOREIGN KEY | customer  | customers.[id] |
| orders | primary                   | PRIMARY KEY | id        | NULL           |
+--------+---------------------------+-------------+-----------+----------------+
> ALTER TABLE orders DROP CONSTRAINT fk_customer_ref_customers;
ALTER TABLE
> SHOW CONSTRAINTS FROM orders;
+--------+---------+-------------+-----------+---------+
| Table  |  Name   |    Type     | Column(s) | Details |
+--------+---------+-------------+-----------+---------+
| orders | primary | PRIMARY KEY | id        | NULL    |
+--------+---------+-------------+-----------+---------+

Note: 不能删除 primary约束,因为该约束表示的是 Primary Key

See Also