1
-- source include/testdb_only.inc
2
-- source include/have_innodb.inc
4
DROP TABLE IF EXISTS t1,t2,t3;
8
# Test for KEY_COLUMN_USAGE & TABLE_CONSTRAINTS tables
11
CREATE TABLE t1 (id INT NOT NULL, PRIMARY KEY (id)) ENGINE=INNODB;
12
CREATE TABLE t2 (id INT PRIMARY KEY, t1_id INT, INDEX par_ind (t1_id, id),
13
FOREIGN KEY (t1_id) REFERENCES t1(id) ON DELETE CASCADE,
14
FOREIGN KEY (t1_id) REFERENCES t1(id) ON UPDATE CASCADE) ENGINE=INNODB;
16
CREATE TABLE t3 (id INT PRIMARY KEY, t2_id INT, INDEX par_ind (t2_id),
17
FOREIGN KEY (id, t2_id) REFERENCES t2(t1_id, id) ON DELETE CASCADE) ENGINE=INNODB;
19
select * from information_schema.TABLE_CONSTRAINTS where
21
select * from information_schema.KEY_COLUMN_USAGE where
24
drop table t3, t2, t1;
27
# Test for REFERENTIAL_CONSTRAINTS table
29
CREATE TABLE t1(a1 INT NOT NULL, a2 INT NOT NULL,
30
PRIMARY KEY(a1, a2)) ENGINE=INNODB;
31
CREATE TABLE t2(b1 INT, b2 INT, INDEX (b1, b2),
33
FOREIGN KEY (b1, b2) REFERENCES t1(a1, a2)
34
ON UPDATE CASCADE ON DELETE NO ACTION) ENGINE=INNODB;
35
CREATE TABLE t3(b1 INT, b2 INT, INDEX t3_indx (b1, b2),
37
FOREIGN KEY (b1, b2) REFERENCES t2(b1, b2)
38
ON UPDATE SET NULL ON DELETE RESTRICT) ENGINE=INNODB;
39
CREATE TABLE t4(b1 INT, b2 INT, UNIQUE KEY t4_ukey (b1, b2),
41
FOREIGN KEY (b1, b2) REFERENCES t3(b1, b2)
42
ON UPDATE NO ACTION ON DELETE SET NULL) ENGINE=INNODB;
43
CREATE TABLE t5(b1 INT, b2 INT, INDEX (b1, b2),
45
FOREIGN KEY (b1, b2) REFERENCES t4(b1, b2)
46
ON UPDATE RESTRICT ON DELETE CASCADE) ENGINE=INNODB;
48
select a.CONSTRAINT_SCHEMA, b.TABLE_NAME, CONSTRAINT_TYPE,
49
b.CONSTRAINT_NAME, UNIQUE_CONSTRAINT_SCHEMA, UNIQUE_CONSTRAINT_NAME,
50
MATCH_OPTION, UPDATE_RULE, DELETE_RULE, b.REFERENCED_TABLE_NAME
51
from information_schema.TABLE_CONSTRAINTS a,
52
information_schema.REFERENTIAL_CONSTRAINTS b
53
where a.CONSTRAINT_SCHEMA = 'test' and a.CONSTRAINT_SCHEMA = b.CONSTRAINT_SCHEMA and
54
a.CONSTRAINT_NAME = b.CONSTRAINT_NAME;
55
drop tables t5, t4, t3, t2, t1;
58
# Bug#25026 `information_schema.KEY_COLUMN_USAGE`.`REFERENCED_TABLE_NAME` returns garbage
60
create database `db-1`;
63
id int(10) unsigned not null auto_increment,
68
id int(10) unsigned not null auto_increment,
69
idtype int(10) unsigned not null,
72
constraint fk_t1_1 foreign key (idtype) references `t-2` (id)
75
select referenced_table_schema, referenced_table_name
76
from information_schema.key_column_usage
77
where constraint_schema = 'db-1';
81
# Bug#35108 SELECT FROM REFERENTIAL_CONSTRAINTS crashes
83
create table t1(id int primary key) engine = Innodb;
84
create table t2(pid int, foreign key (pid) references t1(id)) engine = Innodb;
85
set foreign_key_checks = 0;
87
select UNIQUE_CONSTRAINT_NAME
88
from information_schema.referential_constraints
89
where constraint_schema = schema();
91
set foreign_key_checks = 1;