1
-- source include/testdb_only.inc
3
DROP TABLE IF EXISTS t1,t2,t3;
7
# Test for KEY_COLUMN_USAGE & TABLE_CONSTRAINTS tables
10
CREATE TABLE t1 (id INT NOT NULL, PRIMARY KEY (id)) ENGINE=INNODB;
11
CREATE TABLE t2 (id INT PRIMARY KEY, t1_id INT, INDEX par_ind (t1_id, id),
12
FOREIGN KEY (t1_id) REFERENCES t1(id) ON DELETE CASCADE,
13
FOREIGN KEY (t1_id) REFERENCES t1(id) ON UPDATE CASCADE) ENGINE=INNODB;
15
CREATE TABLE t3 (id INT PRIMARY KEY, t2_id INT, INDEX par_ind (t2_id),
16
FOREIGN KEY (id, t2_id) REFERENCES t2(t1_id, id) ON DELETE CASCADE) ENGINE=INNODB;
18
#select * from information_schema.OLD_TABLE_CONSTRAINTS where
19
#TABLE_SCHEMA= "test";
20
select * from data_dictionary.indexes where TABLE_SCHEMA= "test";
22
drop table t3, t2, t1;
25
# Test for REFERENTIAL_CONSTRAINTS table
27
CREATE TABLE t1(a1 INT NOT NULL, a2 INT NOT NULL,
28
PRIMARY KEY(a1, a2)) ENGINE=INNODB;
29
CREATE TABLE t2(b1 INT, b2 INT, INDEX (b1, b2),
31
FOREIGN KEY (b1, b2) REFERENCES t1(a1, a2)
32
ON UPDATE CASCADE ON DELETE NO ACTION) ENGINE=INNODB;
33
CREATE TABLE t3(b1 INT, b2 INT, INDEX t3_indx (b1, b2),
35
FOREIGN KEY (b1, b2) REFERENCES t2(b1, b2)
36
ON UPDATE SET NULL ON DELETE RESTRICT) ENGINE=INNODB;
37
CREATE TABLE t4(b1 INT, b2 INT, UNIQUE KEY t4_ukey (b1, b2),
39
FOREIGN KEY (b1, b2) REFERENCES t3(b1, b2)
40
ON UPDATE NO ACTION ON DELETE SET NULL) ENGINE=INNODB;
41
CREATE TABLE t5(b1 INT, b2 INT, INDEX (b1, b2),
43
FOREIGN KEY (b1, b2) REFERENCES t4(b1, b2)
44
ON UPDATE RESTRICT ON DELETE CASCADE) ENGINE=INNODB;
46
#select a.CONSTRAINT_SCHEMA, b.TABLE_NAME, CONSTRAINT_TYPE,
47
# b.CONSTRAINT_NAME, UNIQUE_CONSTRAINT_SCHEMA, UNIQUE_CONSTRAINT_NAME,
48
# MATCH_OPTION, UPDATE_RULE, DELETE_RULE, b.REFERENCED_TABLE_NAME
49
#from information_schema.OLD_TABLE_CONSTRAINTS a,
50
# information_schema.OLD_REFERENTIAL_CONSTRAINTS b
51
#where a.CONSTRAINT_SCHEMA = 'test' and a.CONSTRAINT_SCHEMA = b.CONSTRAINT_SCHEMA and
52
#a.CONSTRAINT_NAME = b.CONSTRAINT_NAME;
53
drop tables t5, t4, t3, t2, t1;
56
# Bug#25026 `information_schema.KEY_COLUMN_USAGE`.`REFERENCED_TABLE_NAME` returns garbage
58
create database `db-1`;
61
id int not null auto_increment,
66
id int not null auto_increment,
70
constraint fk_t1_1 foreign key (idtype) references `t-2` (id)
73
#select referenced_table_schema, referenced_table_name
74
#from data_dictionary.indexes
75
#where constraint_schema = 'db-1';
79
# Bug#35108 SELECT FROM REFERENTIAL_CONSTRAINTS crashes
81
create table t1(id int primary key) engine = Innodb;
82
create table t2(pid int, foreign key (pid) references t1(id)) engine = Innodb;
83
set foreign_key_checks = 0;
85
#select UNIQUE_CONSTRAINT_NAME
86
#from data_dictionary.OLD_referential_constraints
87
#where constraint_schema = schema();
89
set foreign_key_checks = 1;