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 infoschema.referential_constraints #6139

Merged
merged 2 commits into from
Aug 12, 2021
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
1 change: 1 addition & 0 deletions TOC.md
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@
+ [`METRICS_TABLES`](/information-schema/information-schema-metrics-tables.md)
+ [`PARTITIONS`](/information-schema/information-schema-partitions.md)
+ [`PROCESSLIST`](/information-schema/information-schema-processlist.md)
+ [`REFERENTIAL_CONSTRAINTS`](/information-schema/information-schema-referential-constraints.md)
+ [`SCHEMATA`](/information-schema/information-schema-schemata.md)
+ [`SEQUENCES`](/information-schema/information-schema-sequences.md)
+ [`SESSION_VARIABLES`](/information-schema/information-schema-session-variables.md)
Expand Down
69 changes: 69 additions & 0 deletions information-schema/information-schema-referential-constraints.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---
title: REFERENTIAL_CONSTRAINTS
summary: Learn the `REFERENTIAL_CONSTRAINTS` information_schema table.
---

# REFERENTIAL_CONSTRAINTS

The `REFERENTIAL_CONSTRAINTS` table provides information about `FOREIGN KEY` relationships between tables. Note that TiDB currently does not enforce `FOREIGN KEY` constraints, or perform actions such as `ON DELETE CASCADE`.

{{< copyable "sql" >}}

```sql
USE information_schema;
DESC referential_constraints;
```

```sql
+---------------------------+--------------+------+------+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------------------+--------------+------+------+---------+-------+
| CONSTRAINT_CATALOG | varchar(512) | NO | | NULL | |
| CONSTRAINT_SCHEMA | varchar(64) | NO | | NULL | |
| CONSTRAINT_NAME | varchar(64) | NO | | NULL | |
| UNIQUE_CONSTRAINT_CATALOG | varchar(512) | NO | | NULL | |
| UNIQUE_CONSTRAINT_SCHEMA | varchar(64) | NO | | NULL | |
| UNIQUE_CONSTRAINT_NAME | varchar(64) | YES | | NULL | |
| MATCH_OPTION | varchar(64) | NO | | NULL | |
| UPDATE_RULE | varchar(64) | NO | | NULL | |
| DELETE_RULE | varchar(64) | NO | | NULL | |
| TABLE_NAME | varchar(64) | NO | | NULL | |
| REFERENCED_TABLE_NAME | varchar(64) | NO | | NULL | |
+---------------------------+--------------+------+------+---------+-------+
11 rows in set (0.00 sec)
```

{{< copyable "sql" >}}

```sql
CREATE TABLE test.parent (
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY (id)
);

CREATE TABLE test.child (
id INT NOT NULL AUTO_INCREMENT,
name varchar(255) NOT NULL,
parent_id INT DEFAULT NULL,
PRIMARY KEY (id),
CONSTRAINT fk_parent FOREIGN KEY (parent_id) REFERENCES parent (id) ON UPDATE CASCADE ON DELETE RESTRICT
);

SELECT * FROM referential_constraints\G
```

```
*************************** 1. row ***************************
CONSTRAINT_CATALOG: def
CONSTRAINT_SCHEMA: test
CONSTRAINT_NAME: fk_parent
UNIQUE_CONSTRAINT_CATALOG: def
UNIQUE_CONSTRAINT_SCHEMA: test
UNIQUE_CONSTRAINT_NAME: PRIMARY
MATCH_OPTION: NONE
UPDATE_RULE: CASCADE
DELETE_RULE: RESTRICT
TABLE_NAME: child
REFERENCED_TABLE_NAME: parent
1 row in set (0.00 sec)
```
2 changes: 1 addition & 1 deletion information-schema/information-schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Many `INFORMATION_SCHEMA` tables have a corresponding `SHOW` command. The benefi
| `PLUGINS` | Not implemented by TiDB. Returns zero rows. |
| [`PROCESSLIST`](/information-schema/information-schema-processlist.md) | Provides similar information to the command `SHOW PROCESSLIST`. |
| `PROFILING` | Not implemented by TiDB. Returns zero rows. |
| `REFERENTIAL_CONSTRAINTS` | Not implemented by TiDB. Returns zero rows. |
| `REFERENTIAL_CONSTRAINTS` | Provides information on `FOREIGN KEY` constraints. |
| `ROUTINES` | Not implemented by TiDB. Returns zero rows. |
| [`SCHEMATA`](/information-schema/information-schema-schemata.md) | Provides similar information to `SHOW DATABASES`. |
| `SCHEMA_PRIVILEGES` | Not implemented by TiDB. Returns zero rows. |
Expand Down