-
Notifications
You must be signed in to change notification settings - Fork 687
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add infoschema.referential_constraints
- Loading branch information
Showing
2 changed files
with
70 additions
and
1 deletion.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
information-schema/information-schema-referential-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,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) | ||
``` |
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