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

Add docs for information_schema.CHECK_CONSTRAINTS #14780

Merged
merged 5 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion TOC-tidb-cloud.md
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@
- INFORMATION_SCHEMA
- [Overview](/information-schema/information-schema.md)
- [`ANALYZE_STATUS`](/information-schema/information-schema-analyze-status.md)
- [`CHECK_CONSTRAINTS`](/information-schema/information-schema-check-constraints.md)
- [`CLIENT_ERRORS_SUMMARY_BY_HOST`](/information-schema/client-errors-summary-by-host.md)
- [`CLIENT_ERRORS_SUMMARY_BY_USER`](/information-schema/client-errors-summary-by-user.md)
- [`CLIENT_ERRORS_SUMMARY_GLOBAL`](/information-schema/client-errors-summary-global.md)
Expand Down Expand Up @@ -611,4 +612,4 @@
- [2021](/tidb-cloud/release-notes-2021.md)
- [2020](/tidb-cloud/release-notes-2020.md)
- Maintenance Notification
- [[2023-08-31] TiDB Cloud Console Maintenance Notification](/tidb-cloud/notification-2023-08-31-console-maintenance.md)
- [[2023-08-31] TiDB Cloud Console Maintenance Notification](/tidb-cloud/notification-2023-08-31-console-maintenance.md)
1 change: 1 addition & 0 deletions TOC.md
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,7 @@
- INFORMATION_SCHEMA
- [Overview](/information-schema/information-schema.md)
- [`ANALYZE_STATUS`](/information-schema/information-schema-analyze-status.md)
- [`CHECK_CONSTRAINTS`](/information-schema/information-schema-check-constraints.md)
- [`CLIENT_ERRORS_SUMMARY_BY_HOST`](/information-schema/client-errors-summary-by-host.md)
- [`CLIENT_ERRORS_SUMMARY_BY_USER`](/information-schema/client-errors-summary-by-user.md)
- [`CLIENT_ERRORS_SUMMARY_GLOBAL`](/information-schema/client-errors-summary-global.md)
Expand Down
52 changes: 52 additions & 0 deletions information-schema/information-schema-check-constraints.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
title: CHECK_CONSTRAINTS
summary: Learn the `CHECK_CONSTRAINTS` INFORMATION_SCHEMA table.
---

# CHECK\_CONSTRAINTS

The `CHECK_CONSTRAINTS` table provides information about [`CHECK` constraints](/constraints.md#check) on tables.

```sql
USE INFORMATION_SCHEMA;
DESC 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 | |
+--------------------+-------------+------+-----+---------+-------+
4 rows in set (0.00 sec)
```

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

```sql
CREATE TABLE test.t1 (id INT PRIMARY KEY, CHECK (id%2 = 0));
SELECT * FROM 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)
1 row in set (0.00 sec)
```

Fields in the `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.