forked from pingcap/docs-cn
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add docs for information_schema.CHECK_CONSTRAINTS (pingcap#15090)
- Loading branch information
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
information-schema/information-schema-check-constraints.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
--- | ||
title: CHECK_CONSTRAINTS | ||
summary: 了解 INFORMATION_SCHEMA 表 `CHECK_CONSTRAINTS`。 | ||
--- | ||
|
||
# CHECK\_CONSTRAINTS | ||
|
||
`CHECK_CONSTRAINTS` 表提供关于表上 [`CHECK` 约束](/constraints.md#check-约束)的信息。 | ||
|
||
```sql | ||
USE INFORMATION_SCHEMA; | ||
DESC CHECK_CONSTRAINTS; | ||
``` | ||
|
||
命令输出如下: | ||
|
||
```sql | ||
+--------------------+-------------+------+-----+---------+-------+ | ||
| Field | Type | Null | Key | Default | Extra | | ||
+--------------------+-------------+------+-----+---------+-------+ | ||
| CONSTRAINT_CATALOG | varchar(64) | NO | | NULL | | | ||
| CONSTRAINT_SCHEMA | varchar(64) | NO | | NULL | | | ||
| CONSTRAINT_NAME | varchar(64) | NO | | NULL | | | ||
| CHECK_CLAUSE | longtext | NO | | NULL | | | ||
+--------------------+-------------+------+-----+---------+-------+ | ||
4 rows in set (0.00 sec) | ||
``` | ||
|
||
下述示例使用 `CREATE TABLE` 语句添加 `CHECK` 约束: | ||
|
||
```sql | ||
CREATE TABLE test.t1 (id INT PRIMARY KEY, CHECK (id%2 = 0)); | ||
SELECT * FROM CHECK_CONSTRAINTS\G | ||
``` | ||
|
||
命令输出如下: | ||
|
||
```sql | ||
*************************** 1. row *************************** | ||
CONSTRAINT_CATALOG: def | ||
CONSTRAINT_SCHEMA: test | ||
CONSTRAINT_NAME: t1_chk_1 | ||
CHECK_CLAUSE: (`id` % 2 = 0) | ||
1 row in set (0.00 sec) | ||
``` | ||
|
||
`CHECK_CONSTRAINTS` 表的字段描述如下: | ||
|
||
* `CONSTRAINT_CATALOG`:约束的目录,始终为 `def`。 | ||
* `CONSTRAINT_SCHEMA`:约束的库名。 | ||
* `CONSTRAINT_NAME`:约束的名字。 | ||
* `CHECK_CLAUSE`:检查约束的子句。 |