Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tidb: add description about TIDB_CHECK_CONSTRAINTS #18753

Merged
merged 5 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions TOC-tidb-cloud.md
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,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_HISTORY`](/information-schema/information-schema-tidb-hot-regions-history.md)
- [`TIDB_INDEXES`](/information-schema/information-schema-tidb-indexes.md)
- [`TIDB_INDEX_USAGE`](/information-schema/information-schema-tidb-index-usage.md)
Expand Down
1 change: 1 addition & 0 deletions TOC.md
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,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 @@ The output is as follows:
The following example adds a `CHECK` constraint using the `CREATE TABLE` statement:

```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: Learn the `TIDB_CHECK_CONSTRAINTS` INFORMATION_SCHEMA table.
---

# TIDB\_CHECK\_CONSTRAINTS

The `TIDB_CHECK_CONSTRAINTS` table provides information about [`CHECK` constraints](/constraints.md#check) on tables. Besides the columns in [`CHECK_CONSTRAINTS`](/information-schema/information-schema-check-constraints.md), `TIDB_CHECK_CONSTRAINTS` provides the table name and table ID that define the `CHECK` constraint.
hfxsd marked this conversation as resolved.
Show resolved Hide resolved

```sql
USE INFORMATION_SCHEMA;
DESC TIDB_CHECK_CONSTRAINTS;
```

The output is as follows:

```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)
```

The following example adds a `CHECK` constraint using the `CREATE TABLE` statement:

```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
```

The output is as follows:

```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)
```

Fields in the `TIDB_CHECK_CONSTRAINTS` table are described as follows:

* `CONSTRAINT_CATALOG`: The catalog of the constraint, which is always `def`.
* `CONSTRAINT_SCHEMA`: The schema of the constraint.
* `CONSTRAINT_NAME`: The name of the constraint.
* `CHECK_CLAUSE`: The clause of the check constraint.
* `TABLE_NAME`: The table name of the constraint.
* `TABLE_ID`: The table id of the constraint.
hfxsd marked this conversation as resolved.
Show resolved Hide resolved
Loading