Skip to content

Commit

Permalink
tidb: add description about TIDB_CHECK_CONSTRAINTS
Browse files Browse the repository at this point in the history
  • Loading branch information
CbcWestwolf committed Sep 11, 2024
1 parent 56faa03 commit 3751c5b
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions TOC.md
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,7 @@
- [`TABLES`](/information-schema/information-schema-tables.md)
- [`TABLE_CONSTRAINTS`](/information-schema/information-schema-table-constraints.md)
- [`TABLE_STORAGE_STATS`](/information-schema/information-schema-table-storage-stats.md)
- [`TIDB_CHECK_CONSTRAINTS`](/information-schema/information-schema-tidb-check-constraints.md)
- [`TIDB_HOT_REGIONS`](/information-schema/information-schema-tidb-hot-regions.md)
- [`TIDB_HOT_REGIONS_HISTORY`](/information-schema/information-schema-tidb-hot-regions-history.md)
- [`TIDB_INDEXES`](/information-schema/information-schema-tidb-indexes.md)
Expand Down
1 change: 1 addition & 0 deletions information-schema/information-schema-check-constraints.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ DESC CHECK_CONSTRAINTS;
下述示例使用 `CREATE TABLE` 语句添加 `CHECK` 约束:

```sql
SET GLOBAL tidb_enable_check_constraint = ON;
CREATE TABLE test.t1 (id INT PRIMARY KEY, CHECK (id%2 = 0));
SELECT * FROM CHECK_CONSTRAINTS\G
```
Expand Down
59 changes: 59 additions & 0 deletions information-schema/information-schema-tidb-check-constraints.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
title: TIDB_CHECK_CONSTRAINTS
summary: 了解 INFORMATION_SCHEMA 表 `TIDB_CHECK_CONSTRAINTS`。
---

# TIDB\_CHECK\_CONSTRAINTS

`TIDB_CHECK_CONSTRAINTS` 表提供关于表上 [`CHECK` 约束](/constraints.md#check-约束)的信息。除了包含 [`CHECK_CONSTRAINTS`](/information-schema/information-schema-check-constraints.md) 中的信息,`TIDB_CHECK_CONSTRAINTS` 还可获取定义 `CHECK` 约束的表名和表 ID。

```sql
USE INFORMATION_SCHEMA;
DESC TIDB_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 | |
| TABLE_NAME | varchar(64) | YES | | NULL | |
| TABLE_ID | bigint(21) | YES | | NULL | |
+--------------------+-------------+------+------+---------+-------+
6 rows in set (0.00 sec)
```

下述示例使用 `CREATE TABLE` 语句添加 `CHECK` 约束:

```sql
SET GLOBAL tidb_enable_check_constraint = ON;
CREATE TABLE test.t1 (id INT PRIMARY KEY, CHECK (id%2 = 0));
SELECT * FROM TIDB_CHECK_CONSTRAINTS\G
```

命令输出如下:

```sql
*************************** 1. row ***************************
CONSTRAINT_CATALOG: def
CONSTRAINT_SCHEMA: test
CONSTRAINT_NAME: t1_chk_1
CHECK_CLAUSE: (`id` % 2 = 0)
TABLE_NAME: t1
TABLE_ID: 107
1 row in set (0.02 sec)
```

`TIDB_CHECK_CONSTRAINTS` 表的字段描述如下:

* `CONSTRAINT_CATALOG`:约束的目录,始终为 `def`
* `CONSTRAINT_SCHEMA`:约束的库名。
* `CONSTRAINT_NAME`:约束的名字。
* `CHECK_CLAUSE`:检查约束的子句。
* `TABLE_NAME`:约束所在的表名。
* `TABLE_ID`:约束所在的表 ID。

0 comments on commit 3751c5b

Please sign in to comment.