2005-09-22 02:23:07 +02:00
|
|
|
DROP TABLE IF EXISTS t1,t2,t3;
|
2004-11-24 17:32:10 +01:00
|
|
|
CREATE TABLE t1 (id INT NOT NULL, PRIMARY KEY (id)) ENGINE=INNODB;
|
2005-05-20 14:39:28 +02:00
|
|
|
CREATE TABLE t2 (id INT PRIMARY KEY, t1_id INT, INDEX par_ind (t1_id, id),
|
2004-11-24 17:32:10 +01:00
|
|
|
FOREIGN KEY (t1_id) REFERENCES t1(id) ON DELETE CASCADE,
|
|
|
|
FOREIGN KEY (t1_id) REFERENCES t1(id) ON UPDATE CASCADE) ENGINE=INNODB;
|
2005-05-20 14:39:28 +02:00
|
|
|
CREATE TABLE t3 (id INT PRIMARY KEY, t2_id INT, INDEX par_ind (t2_id),
|
|
|
|
FOREIGN KEY (id, t2_id) REFERENCES t2(t1_id, id) ON DELETE CASCADE) ENGINE=INNODB;
|
2004-11-24 17:32:10 +01:00
|
|
|
select * from information_schema.TABLE_CONSTRAINTS where
|
|
|
|
TABLE_SCHEMA= "test";
|
2004-12-10 10:07:11 +01:00
|
|
|
CONSTRAINT_CATALOG CONSTRAINT_SCHEMA CONSTRAINT_NAME TABLE_SCHEMA TABLE_NAME CONSTRAINT_TYPE
|
|
|
|
NULL test PRIMARY test t1 PRIMARY KEY
|
|
|
|
NULL test PRIMARY test t2 PRIMARY KEY
|
|
|
|
NULL test t2_ibfk_1 test t2 FOREIGN KEY
|
|
|
|
NULL test t2_ibfk_2 test t2 FOREIGN KEY
|
2005-05-20 14:39:28 +02:00
|
|
|
NULL test PRIMARY test t3 PRIMARY KEY
|
|
|
|
NULL test t3_ibfk_1 test t3 FOREIGN KEY
|
2004-11-24 17:32:10 +01:00
|
|
|
select * from information_schema.KEY_COLUMN_USAGE where
|
|
|
|
TABLE_SCHEMA= "test";
|
2005-05-20 14:39:28 +02:00
|
|
|
CONSTRAINT_CATALOG CONSTRAINT_SCHEMA CONSTRAINT_NAME TABLE_CATALOG TABLE_SCHEMA TABLE_NAME COLUMN_NAME ORDINAL_POSITION POSITION_IN_UNIQUE_CONSTRAINT REFERENCED_TABLE_SCHEMA REFERENCED_TABLE_NAME REFERENCED_COLUMN_NAME
|
|
|
|
NULL test PRIMARY NULL test t1 id 1 NULL NULL NULL NULL
|
|
|
|
NULL test PRIMARY NULL test t2 id 1 NULL NULL NULL NULL
|
|
|
|
NULL test t2_ibfk_1 NULL test t2 t1_id 1 1 test t1 id
|
|
|
|
NULL test t2_ibfk_2 NULL test t2 t1_id 1 1 test t1 id
|
|
|
|
NULL test PRIMARY NULL test t3 id 1 NULL NULL NULL NULL
|
|
|
|
NULL test t3_ibfk_1 NULL test t3 id 1 1 test t2 t1_id
|
|
|
|
NULL test t3_ibfk_1 NULL test t3 t2_id 2 2 test t2 id
|
|
|
|
drop table t3, t2, t1;
|